diff --git a/app/data/controller/Member.php b/app/data/controller/Member.php new file mode 100644 index 000000000..c04f4af18 --- /dev/null +++ b/app/data/controller/Member.php @@ -0,0 +1,50 @@ +title = '会员用户管理'; + $query = $this->_query($this->table); + $query->like('phone,username|nickname#username'); + $query->whereRaw('nickname != "" or username != ""'); + $query->order('id desc')->equal('status')->dateBetween('create_at')->page(); + } + + /** + * 修改会员状态 + * @auth true + * @throws \think\db\exception\DbException + */ + public function state() + { + $this->_save($this->table, $this->_vali([ + 'status.in:0,1' => '状态值范围异常!', + 'status.require' => '状态值不能为空!', + ])); + } + +} \ No newline at end of file diff --git a/app/data/controller/ShopGoodsSpec.php b/app/data/controller/ShopGoodsSpec.php deleted file mode 100644 index 006c57bda..000000000 --- a/app/data/controller/ShopGoodsSpec.php +++ /dev/null @@ -1,20 +0,0 @@ -title = '订单数据管理'; + // 订单各状态数据统计 + $this->totals = [0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 'all' => 0]; + $this->app->db->name($this->table)->fieldRaw('status,count(1) total')->group('status')->select()->map(function ($vo) { + $this->totals[$vo['status']] = $vo['total']; + $this->totals["all"] += $vo['total']; + }); + // 订单列表查询 + $query = $this->_query($this->table)->dateBetween('create_at,payment_datetime')->equal('status,payment_status'); + $query->like('order_no,express_send_no,express_name,express_phone,express_province,express_city,express_area,express_address'); + $query->dateBetween('create_at,pay_datetime')->equal('status,pay_state'); + // 会员搜索查询 + $db = $this->_query('DataMember')->like('phone#member_phone,nickname#member_nickname')->db(); + if ($db->getOptions('where')) $query->whereRaw("mid in {$db->fieldRaw('id')->buildSql()}"); + // 推荐人搜索查询 + $db = $this->_query('DataMember')->like('phone#agent_phone,nickname#agent_nickname')->db(); + if ($db->getOptions('where')) $query->whereRaw("from in {$db->fieldRaw('id')->buildSql()}"); + // 列表选项卡 + $this->type = input('type', 'all'); + if (is_numeric($this->type)) $query->equal('status#type'); + // 分页排序处理 + if (isset($this->action) && $this->action === 'export') { + return $query; + } else { + $query->order('id desc')->page(); + } + } + + /** + * 导出订单数据 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function export() + { + $this->action = 'export'; + $options = ['serialize' => serialize($this->index()->db()->getOptions())]; + $this->_queue('导出订单数据', OrderQueue::class, 0, $options, 0); + } + + /** + * 订单列表处理 + * @param array $data + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected function _index_page_filter(array &$data) + { + $mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from_mid'))); + $members = $this->app->db->name('DataMember')->whereIn('id', $mids)->column('*', 'id'); + $orderNos = array_unique(array_column($data, 'order_no')); + $goodsList = $this->app->db->name('ShopOrderItem')->whereIn('order_no', $orderNos)->select()->toArray(); + foreach ($data as &$vo) { + [$vo['member'], $vo['from_member'], $vo['list']] = [[], [], []]; + $vo['member'] = isset($members[$vo['mid']]) ? $members[$vo['mid']] : []; + $vo['from_member'] = isset($members[$vo['from_mid']]) ? $members[$vo['from_mid']] : []; + foreach ($goodsList as $goods) if ($goods['order_no'] === $vo['order_no']) $vo['list'][] = $goods; + } + } + + /** + * 修改快递管理 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function express() + { + if ($this->request->isGet()) { + $where = ['is_deleted' => '0', 'status' => '1']; + $query = $this->app->db->name('ShopExpressCompany')->where($where); + $this->expressList = $query->order('sort desc,id desc')->select()->toArray(); + } + $this->_form($this->table); + } + + /** + * 快递追踪查询 + * @auth true + */ + public function expressQuery() + { + try { + $data = $this->_vali([ + 'code.require' => '快递公司不能为空!', + 'number.require' => '配送单号不能为空!', + ]); + $this->result = OpenCuciService::instance()->track($data['code'], $data['number']); + if (empty($this->result['code'])) $this->error($this->result['info']); + $this->fetch(); + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $exception) { + $this->error($exception->getMessage()); + } + } + + /** + * 快递表单处理 + * @param array $vo + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + protected function _express_form_filter(&$vo) + { + if ($this->request->isPost()) { + $order = $this->app->db->name($this->table)->where(['id' => $vo['id']])->find(); + if (empty($order)) $this->error('订单查询异常,请稍候再试!'); + $map = ['code_1|code_2|code_3' => $vo['express_company_code']]; + $express = $this->app->db->name('ShopExpressCompany')->where($map)->find(); + if (empty($express)) $this->error('配送快递公司异常,请重新选择快递公司!'); + $vo['express_company_title'] = $express['title']; + $vo['express_send_at'] = empty($order['express_send_at']) ? date('Y-m-d H:i:s') : $order['express_send_at']; + $vo['express_state'] = '1'; + $vo['status'] = '4'; + } + } + + /** + * 取消订单并创建售后单 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function cancel() + { + $map = $this->_vali(['order_no.require' => '订单编号不能为空!']); + $order = $this->app->db->name($this->table)->where($map)->find(); + if (empty($order)) $this->error('订单查询异常'); + if (intval($order['status']) !== 3) $this->error('该订单不能发货!'); + [$rules, $data] = [[], ['type' => 3, 'refund_content' => '后台操作取消订单并申请退款', 'refund_images' => '']]; + foreach ($this->app->db->name("{$this->table}List")->where($map)->select()->toArray() as $item) { + $rules[] = ['goods_id' => $item['goods_id'], 'goods_spec' => $item['goods_spec'], 'refund_number' => $item['number_goods']]; + } + try { + if (OrderService::instance()->refund($order['order_no'], $data, $rules)) { + $this->app->db->name($this->table)->where($map)->update([ + 'status' => 0, + 'cancel_state' => 1, + 'cancel_datetime' => date('Y-m-d H:i:s'), + 'cancel_description' => '后台操作取消并创建退款申请', + ]); + $this->success('取消订单并创建退款申请成功!'); + } + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $exception) { + $this->error($exception->getMessage()); + } + } } \ No newline at end of file diff --git a/app/data/controller/ShopOrderSend.php b/app/data/controller/ShopOrderSend.php new file mode 100644 index 000000000..fd8d6745a --- /dev/null +++ b/app/data/controller/ShopOrderSend.php @@ -0,0 +1,34 @@ +_query($this->table); + $query->page(); + } + +} \ No newline at end of file diff --git a/app/data/controller/ShopOrderService.php b/app/data/controller/ShopOrderService.php new file mode 100644 index 000000000..0c60c3bef --- /dev/null +++ b/app/data/controller/ShopOrderService.php @@ -0,0 +1,34 @@ +_query($this->table); + $query->page(); + } + +} \ No newline at end of file diff --git a/app/data/service/OrderService.php b/app/data/service/OrderService.php new file mode 100644 index 000000000..ef2b8601a --- /dev/null +++ b/app/data/service/OrderService.php @@ -0,0 +1,73 @@ + $orderNo]]; + $order = $this->app->db->name('StoreOrder')->where($map)->find(); + $olist = $this->app->db->name('StoreOrderList')->where($map)->select()->toArray(); + $rlist = $this->app->db->name('StoreOrderRefund')->where($map)->whereIn('refund_status', [1, 2, 3])->select()->toArray(); + $discountRate = $order['pay_price'] / $order['price_discount']; + if (count($olist) > 0) foreach ($olist as &$vo) { + $vo['discount_unit_amount'] = $vo['discount_amount'] / $vo['number_goods'] * $discountRate; + if (count($rlist) > 0) foreach ($rlist as $rule) { + if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) { + $vo['number_goods'] -= $rule['refund_number']; + } + } + } + // dump($olist); + $data['group_no'] = CodeExtend::uniqidDate(18, "G"); + if (count($olist) > 0 && count($rules) > 0) foreach ($olist as &$vo) { + foreach ($rules as $rule) if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) { + if ($vo['number_goods'] - $rule['refund_number'] < 0) { + throw new \think\Exception("订单商品数量异常!"); + } + $data['mid'] = $vo['mid']; + $data['order_no'] = $orderNo; + $data['goods_id'] = $vo['goods_id']; + $data['goods_sku'] = $vo['goods_sku']; + $data['goods_title'] = $vo['goods_title']; + $data['goods_logo'] = $vo['goods_logo']; + $data['goods_spec'] = $vo['goods_spec']; + $data['number_goods'] = $vo['number_goods']; + $data['goods_price_total'] = $vo['goods_price_total']; + $data['goods_price_market'] = $vo['goods_price_market']; + $data['refund_no'] = CodeExtend::uniqidDate(18, 'R'); + $data['refund_rate'] = $discountRate; + $data['refund_number'] = $rule['refund_number']; + $data['refund_amount'] = $rule['refund_number'] * $vo['discount_unit_amount']; + $data['refund_status'] = 1; + $data['discount_amount'] = $vo['discount_amount']; + // 支付金额处理 + if ($order['pay_price'] < $data['refund_amount']) { + $data['refund_amount'] = $order['pay_price']; + } + $all[] = $data; + } + } + if (empty($all)) throw new \think\Exception("没有需要处理的商品!"); + return $this->app->db->name('StoreOrderRefund')->strict(false)->insertAll($all) !== false; + } +} \ No newline at end of file diff --git a/app/data/view/member/index.html b/app/data/view/member/index.html new file mode 100644 index 000000000..511221376 --- /dev/null +++ b/app/data/view/member/index.html @@ -0,0 +1,61 @@ +{extend name="../../admin/view/main"} + +{block name="content"} +
+ + | +姓名昵称 | +会员手机 | +会员状态 | +注册时间 | ++ |
---|---|---|---|---|---|
+ + | +
+ {notempty name='vo.headimg'}
+
+ 姓名:{$vo.username|default='-'}
+ {/if}
+ + 昵称:{$vo.nickname|default='-'} + |
+ {$vo.phone|default='-'} | ++ {if $vo.status eq 0}已冻结{/if} + {if $vo.status eq 1}使用中{/if} + | +{$vo.create_at|default=''} | ++ {if auth("state") and $vo.status eq 1} + 冻结账号 + {/if} + + {if auth("state") and $vo.status eq 0} + 解冻账号 + {/if} + | +
{$vo.context|default='--'}
++ + | +会员信息 | +订单信息 | +发货信息 | +商品信息 | +
---|---|---|---|---|
+ + | +
+
+
+ ![]()
+ 推荐会员:{$vo.from_member.nickname|default='--'}
+ + 推荐手机:{$vo.from_member.phone|default='--'}{notempty name='vo.from_member.vip_level'} [ VIP{$vo.from_member.vip_level} ] {$vo.from_member.vip_title}{/notempty} +
+
+ ![]()
+ 会员昵称:{$vo.member.nickname|default='--'}
+ + 会员手机:{$vo.member.phone|default='--'}{notempty name='vo.member.vip_level'} [ VIP{$vo.member.vip_level} ] {$vo.member.vip_title}{/notempty} + |
+
+
+ {eq name='vo.status' value='0'}已取消{/eq}
+ {eq name='vo.status' value='1'}预订单{/eq}
+ {eq name='vo.status' value='2'}待付款{/eq}
+ {eq name='vo.status' value='3'}待发货{/eq}
+ {eq name='vo.status' value='4'}已发货{/eq}
+ {eq name='vo.status' value='5'}已完成{/eq}
+
+
+ 订单单号:{$vo.order_no|default=''}
+ + 订单金额:{$vo.price_total+0} 元{if $vo.price_express>0}(含{$vo.price_express+0}元){else}(包邮){/if}已支付 {$vo.pay_price+0} 元 + 下单时间:{$vo.create_at|format_datetime} + 支付时间:{$vo.pay_datetime|format_datetime}{if $vo.pay_datetime} ({$vo.pay_type|default='-'}){/if} + |
+
+ 收货信息:{$vo.express_name|default='--'}{$vo.express_phone} + 收货地址:{$vo.express_province|default='--'}{$vo.express_city}{$vo.express_area}{$vo.express_address} + 发货状态:{eq name='vo.express_state' value='0'} + 未发货 + {else} + {$vo.express_company_title|default='--'} + {$vo.express_send_no|default='--'} + {/eq} + {if $vo.status eq 3} + 填写发货 + + 提交仓库 + + + 取消并退款 + + {elseif $vo.status eq 4} + 修改发货 + {/if} + + 发货时间:{$vo.express_send_at|format_datetime} + |
+
+ {foreach $vo.list as $g}
+
+ {if $g.vip_mod > 0 and $g.vip_level > $g.discount_vip}
+ [ VIP{$g.discount_vip} VIP{$g.vip_level} ]
+ {else}
+ [ VIP{$g.discount_vip} ]
+ {/if}
+ {if $g.discount_rate<100.00}
+ 享{$g.discount_rate+0}%折扣
+ x
+ {/if}
+ {$g.number_goods|default=0}件
+ x
+ {$g.goods_price_market+0}元
+ {$g.goods_title|default=''} ( {$g.goods_spec|show_goods_spec})
+
+ {/foreach}
+ |
+
+ + | +会员信息 | +订单信息 | +发货信息 | +商品信息 | +
---|---|---|---|---|
+ + | +
+
+
+ ![]()
+ 推荐会员:{$vo.from_member.nickname|default='--'}
+ + 推荐手机:{$vo.from_member.phone|default='--'}{notempty name='vo.from_member.vip_level'} [ VIP{$vo.from_member.vip_level} ] {$vo.from_member.vip_title}{/notempty} +
+
+ ![]()
+ 会员昵称:{$vo.member.nickname|default='--'}
+ + 会员手机:{$vo.member.phone|default='--'}{notempty name='vo.member.vip_level'} [ VIP{$vo.member.vip_level} ] {$vo.member.vip_title}{/notempty} + |
+
+
+ {eq name='vo.status' value='0'}已取消{/eq}
+ {eq name='vo.status' value='1'}预订单{/eq}
+ {eq name='vo.status' value='2'}待付款{/eq}
+ {eq name='vo.status' value='3'}待发货{/eq}
+ {eq name='vo.status' value='4'}已发货{/eq}
+ {eq name='vo.status' value='5'}已完成{/eq}
+
+
+ 订单单号:{$vo.order_no|default=''}
+ + 订单金额:{$vo.price_total+0} 元{if $vo.price_express>0}(含{$vo.price_express+0}元){else}(包邮){/if}已支付 {$vo.pay_price+0} 元 + 下单时间:{$vo.create_at|format_datetime} + 支付时间:{$vo.pay_datetime|format_datetime}{if $vo.pay_datetime} ({$vo.pay_type|default='-'}){/if} + |
+
+ 收货信息:{$vo.express_name|default='--'}{$vo.express_phone} + 收货地址:{$vo.express_province|default='--'}{$vo.express_city}{$vo.express_area}{$vo.express_address} + 发货状态:{eq name='vo.express_state' value='0'} + 未发货 + {else} + {$vo.express_company_title|default='--'} + {$vo.express_send_no|default='--'} + {/eq} + {if $vo.status eq 3} + 填写发货 + + 提交仓库 + + + 取消并退款 + + {elseif $vo.status eq 4} + 修改发货 + {/if} + + 发货时间:{$vo.express_send_at|format_datetime} + |
+
+ {foreach $vo.list as $g}
+
+ {if $g.vip_mod > 0 and $g.vip_level > $g.discount_vip}
+ [ VIP{$g.discount_vip} VIP{$g.vip_level} ]
+ {else}
+ [ VIP{$g.discount_vip} ]
+ {/if}
+ {if $g.discount_rate<100.00}
+ 享{$g.discount_rate+0}%折扣
+ x
+ {/if}
+ {$g.number_goods|default=0}件
+ x
+ {$g.goods_price_market+0}元
+ {$g.goods_title|default=''} ( {$g.goods_spec|show_goods_spec})
+
+ {/foreach}
+ |
+
+ + | +会员信息 | +订单信息 | +发货信息 | +商品信息 | +
---|---|---|---|---|
+ + | +
+
+
+ ![]()
+ 推荐会员:{$vo.from_member.nickname|default='--'}
+ + 推荐手机:{$vo.from_member.phone|default='--'}{notempty name='vo.from_member.vip_level'} [ VIP{$vo.from_member.vip_level} ] {$vo.from_member.vip_title}{/notempty} +
+
+ ![]()
+ 会员昵称:{$vo.member.nickname|default='--'}
+ + 会员手机:{$vo.member.phone|default='--'}{notempty name='vo.member.vip_level'} [ VIP{$vo.member.vip_level} ] {$vo.member.vip_title}{/notempty} + |
+
+
+ {eq name='vo.status' value='0'}已取消{/eq}
+ {eq name='vo.status' value='1'}预订单{/eq}
+ {eq name='vo.status' value='2'}待付款{/eq}
+ {eq name='vo.status' value='3'}待发货{/eq}
+ {eq name='vo.status' value='4'}已发货{/eq}
+ {eq name='vo.status' value='5'}已完成{/eq}
+
+
+ 订单单号:{$vo.order_no|default=''}
+ + 订单金额:{$vo.price_total+0} 元{if $vo.price_express>0}(含{$vo.price_express+0}元){else}(包邮){/if}已支付 {$vo.pay_price+0} 元 + 下单时间:{$vo.create_at|format_datetime} + 支付时间:{$vo.pay_datetime|format_datetime}{if $vo.pay_datetime} ({$vo.pay_type|default='-'}){/if} + |
+
+ 收货信息:{$vo.express_name|default='--'}{$vo.express_phone} + 收货地址:{$vo.express_province|default='--'}{$vo.express_city}{$vo.express_area}{$vo.express_address} + 发货状态:{eq name='vo.express_state' value='0'} + 未发货 + {else} + {$vo.express_company_title|default='--'} + {$vo.express_send_no|default='--'} + {/eq} + {if $vo.status eq 3} + 填写发货 + + 提交仓库 + + + 取消并退款 + + {elseif $vo.status eq 4} + 修改发货 + {/if} + + 发货时间:{$vo.express_send_at|format_datetime} + |
+
+ {foreach $vo.list as $g}
+
+ {if $g.vip_mod > 0 and $g.vip_level > $g.discount_vip}
+ [ VIP{$g.discount_vip} VIP{$g.vip_level} ]
+ {else}
+ [ VIP{$g.discount_vip} ]
+ {/if}
+ {if $g.discount_rate<100.00}
+ 享{$g.discount_rate+0}%折扣
+ x
+ {/if}
+ {$g.number_goods|default=0}件
+ x
+ {$g.goods_price_market+0}元
+ {$g.goods_title|default=''} ( {$g.goods_spec|show_goods_spec})
+
+ {/foreach}
+ |
+