diff --git a/app/common/controller/Order.php b/app/common/controller/Order.php new file mode 100644 index 0000000..8a3e60f --- /dev/null +++ b/app/common/controller/Order.php @@ -0,0 +1,1146 @@ + +// +---------------------------------------------------------------------- + +namespace app\common\controller; + + +use app\jobs\BatchHandleJob; +use app\Request; +use app\services\activity\coupon\StoreCouponIssueServices; +use app\services\order\store\WriteOffOrderServices; +use app\services\order\StoreOrderCartInfoServices; +use app\services\order\StoreOrderCreateServices; +use app\services\order\StoreOrderDeliveryServices; +use app\services\order\StoreOrderRefundServices; +use app\services\order\StoreOrderServices; +use app\services\order\StoreOrderStatusServices; +use app\services\order\StoreOrderTakeServices; +use app\services\order\StoreOrderWriteOffServices; +use app\services\order\StoreOrderPromotionsServices; +use app\services\order\supplier\SupplierOrderServices; +use app\services\pay\OrderOfflineServices; +use app\services\other\queue\QueueServices; +use app\services\serve\ServeServices; +use app\services\other\ExpressServices; +use app\services\store\SystemStoreServices; +use app\services\supplier\SystemSupplierServices; +use app\services\user\UserServices; +use app\validate\admin\order\StoreOrderValidate; +use crmeb\services\SystemConfigService; +use crmeb\traits\MacroTrait; + +/** + * Trait Order + * @package app\common\controller + * @property StoreOrderServices $services + */ +trait Order +{ + use MacroTrait; + + /** + * 获取订单类型数量 + * @param Request $request + * @return mixed + */ + public function chart(Request $request) + { + $where = $request->getMore([ + ['status', ''], + ['real_name', ''], + ['data', '', '', 'time'], + ['type', ''], + ['plat_type', 0], + ['pay_type', ''], + ['field_key', ''], + ['store_id', ''], + ['supplier_id', ''] + ]); + $where['type'] = trim($where['type']); + if (!in_array($where['status'], [-1, -2, -3])) { + $where['pid'] = [0, -1]; + } + $where['type'] = trim($where['type'], ' '); + $data = $this->services->orderCount($where); + return app('json')->success($data); + } + + /** + * 获取订单列表 + * @param Request $request + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function lst(Request $request) + { + $where = $request->getMore([ + ['status', ''], + ['real_name', ''], + ['is_del', ''], + ['data', '', '', 'time'], + ['type', ''], + ['pay_type', ''], + ['plat_type', -1], + ['order', ''], + ['field_key', ''], + ['store_id', ''], + ['supplier_id', ''] + ]); + $where['type'] = trim($where['type']); + $where['is_system_del'] = 0; + if ($where['store_id'] || $where['supplier_id'] || in_array($where['plat_type'], [0, 1, 2])) { + $where['pid'] = 0; + } elseif (!in_array($where['status'], [-1, -2, -3])) { + $where['pid'] = [0, -1]; + } + $where['type'] = trim($where['type'], ' '); + return app('json')->success($this->services->getOrderList($where, ['*'], ['split' => function ($query) { + $query->field('id,pid'); + }, 'pink', 'invoice'])); + } + + /** + * 获取订单拆分子订单列表 + * @return mixed + */ + public function split_order(Request $request, $id) + { + [$status] = $request->getMore([ + ['status', -1] + ], true); + if (!$id) { + return app('json')->fail('缺少订单ID'); + } + $where = ['pid' => $id, 'is_system_del' => 0]; + if (!$this->services->count($where)) { + $where = ['id' => $id, 'is_system_del' => 0]; + } + return app('json')->success($this->services->getSplitOrderList($where, ['*'], ['split', 'pink', 'invoice', 'supplier', 'store' => function ($query) { + $query->field('id,name')->bind(['store_name' => 'name']); + }])); + } + + /** + * 核销码核销 + * @param Request $request + * @param WriteOffOrderServices $writeOffOrderServices + * @return \think\Response + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function write_order(Request $request, WriteOffOrderServices $writeOffOrderServices) + { + [$code, $confirm] = $request->getMore([ + ['code', ''], + ['confirm', 0] + ], true); + if (!$code) return app('json')->fail('Lack of write-off code'); + $orderInfo = $writeOffOrderServices->writeoffOrderInfo(0, $code, 0); + if ($confirm == 0) { + return app('json')->success('验证成功', $orderInfo); + } + $writeOffOrderServices->writeoffOrder(0, $orderInfo, [], 0); + return app('json')->success('Write off successfully'); + } + + /** + * 订单号核销 + * @param WriteOffOrderServices $writeOffOrderServices + * @param $order_id + * @return \think\Response + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function write_update(WriteOffOrderServices $writeOffOrderServices, $order_id) + { + $orderInfo = $this->services->getOne(['order_id' => $order_id, 'is_del' => 0], '*', ['pink']); + if (!$orderInfo || $orderInfo->shipping_type != 2 && $orderInfo->delivery_type != 'send') { + return app('json')->fail('核销订单未查到!'); + } else { + if (!$orderInfo->verify_code) { + return app('json')->fail('Lack of write-off code'); + } + $orderInfo = $writeOffOrderServices->writeOffOrder(0, $orderInfo->toArray(), [], 0); + if ($orderInfo) { + return app('json')->success('Write off successfully'); + } else { + return app('json')->fail('核销失败!'); + } + } + } + + /** + * 修改支付金额等 + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id) + { + if (!$id) return app('json')->fail('Data does not exist!'); + return app('json')->success($this->services->updateForm($id)); + } + + /** + * 修改订单 + * @param $id + * @return mixed + */ + public function update($id) + { + if (!$id) return app('json')->fail('Missing order ID'); + $data = $this->request->postMore([ + ['order_id', ''], + ['total_price', 0], + ['total_postage', 0], + ['pay_price', 0], + ['pay_postage', 0], + ['gain_integral', 0], + ]); + + $this->validate($data, StoreOrderValidate::class); + + if ($data['total_price'] < 0) return app('json')->fail('Please enter the total price'); + if ($data['pay_price'] < 0) return app('json')->fail('Please enter the actual payment amount'); + + $this->services->updateOrder((int)$id, $data); + return app('json')->success('Modified success'); + } + + /** + * 获取快递公司 + * @param Request $request + * @param ExpressServices $services + * @return mixed + */ + public function express(Request $request, ExpressServices $services) + { + [$status] = $request->getMore([ + ['status', ''], + ], true); + if ($status != '' && $status != 'undefined') $data['status'] = (int)$status; + $data['is_show'] = 1; + return app('json')->success($services->express($data)); + } + + /** + * 批量删除用户已经删除的订单 + * @param Request $request + * @return mixed + */ + public function del_orders(Request $request) + { + [$ids, $all, $where] = $request->postMore([ + ['ids', []], + ['all', 0], + ['where', []], + ], true); + if (!count($ids) && $all == 0) return app('json')->fail('请选择需要删除的订单'); + if ($this->services->getOrderIdsCount($ids) && $all == 0) return app('json')->fail('您选择的的订单存在用户未删除的订单'); + if ($all == 0 && $this->services->batchUpdate($ids, ['is_system_del' => 1])) return app('json')->success('删除成功'); + if ($all == 1) $ids = []; + $type = 6;// 订单删除 + $where['status'] = -4; + /** @var QueueServices $queueService */ + $queueService = app()->make(QueueServices::class); + $queueService->setQueueData($where, 'id', $ids, $type); + //加入队列 + BatchHandleJob::dispatch([false, $type]); + return app('json')->success('后台程序已执行批量删除任务!'); + + } + + /** + * 删除订单 + * @param $id + * @return mixed + */ + public function del($id) + { + if (!$id || !($orderInfo = $this->services->get($id))) + return app('json')->fail('订单不存在'); + if (!$orderInfo->is_del) + return app('json')->fail('订单用户未删除无法删除'); + $orderInfo->is_system_del = 1; + if ($orderInfo->save()) + return app('json')->success('SUCCESS'); + else + return app('json')->fail('ERROR'); + } + + /** + * 订单发送货 + * @param Request $request + * @param StoreOrderDeliveryServices $services + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function update_delivery(Request $request, StoreOrderDeliveryServices $services, $id) + { + $data = $request->postMore([ + ['type', 1], + + ['delivery_name', ''],//快递公司名称 + ['delivery_id', ''],//快递单号 + ['delivery_code', ''],//快递公司编码 + + ['express_record_type', 2],//发货记录类型 + ['express_temp_id', ""],//电子面单模板 + ['to_name', ''],//寄件人姓名 + ['to_tel', ''],//寄件人电话 + ['to_addr', ''],//寄件人地址 + + ['sh_delivery_name', ''],//送货人姓名 + ['sh_delivery_id', ''],//送货人电话 + ['sh_delivery_uid', ''],//送货人ID + ['delivery_type', 1],//送货类型 + ['station_type', 1],//送货类型 + ['cargo_weight', 0],//重量 + ['mark', '', '', 'remark'],//管理员备注 + ['remark', '', '', 'delivery_remark'],//第三方配送备注 + + ['fictitious_content', '']//虚拟发货内容 + ]); + if (!$id) { + return app('json')->fail('缺少发货ID'); + } + return app('json')->success('SUCCESS', $services->delivery((int)$id, $data)); + } + + /** + * 订单拆单发送货 + * @param Request $request + * @param StoreOrderDeliveryServices $services + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function split_delivery(Request $request, StoreOrderDeliveryServices $services, $id) + { + $data = $request->postMore([ + ['type', 1], + ['delivery_name', ''],//快递公司名称 + ['delivery_id', ''],//快递单号 + ['delivery_code', ''],//快递公司编码 + + ['express_record_type', 2],//发货记录类型 + ['express_temp_id', ""],//电子面单模板 + ['to_name', ''],//寄件人姓名 + ['to_tel', ''],//寄件人电话 + ['to_addr', ''],//寄件人地址 + + ['sh_delivery_name', ''],//送货人姓名 + ['sh_delivery_id', ''],//送货人电话 + ['sh_delivery_uid', ''],//送货人ID + ['delivery_type', 1],//送货类型 + ['station_type', 1],//送货类型 + ['cargo_weight', 0],//重量 + ['mark', ''],//备注 + ['remark', ''],//配送备注 + + ['fictitious_content', ''],//虚拟发货内容 + + ['cart_ids', []] + ]); + if (!$id) { + return app('json')->fail('缺少发货ID'); + } + if (!$data['cart_ids']) { + return app('json')->fail('请选择发货商品'); + } + foreach ($data['cart_ids'] as $cart) { + if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) { + return app('json')->fail('请重新选择发货商品,或发货件数'); + } + } + $services->splitDelivery((int)$id, $data); + return app('json')->success('SUCCESS'); + } + + /** + * 获取订单可拆分发货商品列表 + * @param StoreOrderCartInfoServices $services + * @param $id + * @return mixed + */ + public function split_cart_info(StoreOrderCartInfoServices $services, $id) + { + if (!$id) { + return app('json')->fail('缺少发货ID'); + } + return app('json')->success($services->getSplitCartList((int)$id)); + } + + /** + * 获取核销订单商品列表 + * @param Request $request + * @param WriteOffOrderServices $writeOffOrderServices + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function orderCartInfo(Request $request, WriteOffOrderServices $writeOffOrderServices) + { + [$oid] = $request->postMore([ + ['oid', ''] + ], true); + return app('json')->success($writeOffOrderServices->getOrderCartInfo(0, (int)$oid, 1, (int)$this->storeStaffId)); + } + + /** + * 核销订单 + * @param Request $request + * @param WriteOffOrderServices $writeOffOrderServices + * @param $order_id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function wirteoff(Request $request, WriteOffOrderServices $writeOffOrderServices, $order_id) + { + $orderInfo = $this->services->getOne(['order_id' => $order_id, 'is_del' => 0], '*', ['pink']); + if (!$orderInfo) { + return app('json')->fail('核销订单未查到!'); + } + [$cart_ids] = $request->postMore([ + ['cart_ids', []] + ], true); + if ($cart_ids) { + foreach ($cart_ids as $cart) { + if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) { + return app('json')->fail('请重新选择发货商品,或发货件数'); + } + } + } + return app('json')->success('核销成功', $writeOffOrderServices->writeoffOrder(0, $orderInfo->toArray(), $cart_ids, 1, (int)$this->storeStaffId)); + } + + /** + * 确认收货 + * @param StoreOrderTakeServices $services + * @param $id + * @return mixed + */ + public function take_delivery(StoreOrderTakeServices $services, $id) + { + if (!$id) return app('json')->fail('缺少参数'); + $order = $this->services->get($id); + if (!$order) + return app('json')->fail('Data does not exist!'); + if ($order['status'] == 2) + return app('json')->fail('不能重复收货!'); + if ($order['paid'] == 1 && $order['status'] == 1) + $data['status'] = 2; + else if ($order['pay_type'] == 'offline') + $data['status'] = 2; + else + return app('json')->fail('请先发货或者送货!'); + + if ($services->count(['pid' => $id])) { + return app('json')->fail('该订单已拆分发货!'); + } + + if (!$this->services->update($id, $data)) { + return app('json')->fail('收货失败,请稍候再试!'); + } else { + $services->storeProductOrderUserTakeDelivery($order); + return app('json')->success('收货成功'); + } + } + + + /** + * 获取配置信息 + * @return mixed + */ + public function getDeliveryInfo() + { + $data = SystemConfigService::more([ + 'config_export_temp_id', + 'config_export_to_name', + 'config_export_id', + 'config_export_to_tel', + 'config_export_to_address', + 'config_export_open', + 'city_delivery_status', + 'self_delivery_status', + 'dada_delivery_status', + 'uu_delivery_status' + ]); + return app('json')->success([ + 'express_temp_id' => $data['config_export_temp_id'] ?? '', + 'id' => $data['config_export_id'] ?? '', + 'to_name' => $data['config_export_to_name'] ?? '', + 'to_tel' => $data['config_export_to_tel'] ?? '', + 'to_add' => $data['config_export_to_address'] ?? '', + 'export_open' => (bool)((int)($data['config_export_open'] ?? 0)), + 'city_delivery_status' => $data['city_delivery_status'] && ($data['self_delivery_status'] || $data['dada_delivery_status'] || $data['uu_delivery_status']), + 'self_delivery_status' => $data['city_delivery_status'] && $data['self_delivery_status'], + 'dada_delivery_status' => $data['city_delivery_status'] && $data['dada_delivery_status'], + 'uu_delivery_status' => $data['city_delivery_status'] && $data['uu_delivery_status'], + ]); + } + + /** + * 订单主动退款表单生成 + * @param StoreOrderRefundServices $services + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function refund(StoreOrderRefundServices $services, $id) + { + if (!$id) { + return app('json')->fail('Data does not exist!'); + } + return app('json')->success($services->refundOrderForm((int)$id, 'order')); + } + + /** + * 订单主动退款 + * @param Request $request + * @param StoreOrderRefundServices $services + * @param $id + * @return mixed + */ + public function update_refund(Request $request, StoreOrderRefundServices $services, StoreOrderCreateServices $storeOrderCreateServices, StoreOrderCartInfoServices $storeOrderCartInfoServices, $id) + { + $data = $request->postMore([ + ['refund_price', 0], + ['type', 1] + ]); + if (!$id) { + return $this->fail('Data does not exist!'); + } + $data['refund_price'] = sprintf("%.2f", $data['refund_price']); + $order = $this->services->get($id); + if (!$order) { + return $this->fail('Data does not exist!'); + } + if ($services->count(['store_order_id' => $id, 'refund_type' => [0, 1, 2, 4, 5], 'is_cancel' => 0, 'is_del' => 1])) { + return $this->fail('请先处理售后申请'); + } + //0元退款 + if ($order['pay_price'] == 0 && in_array($order['refund_status'], [0, 1])) { + $refund_price = 0; + } else { + if ($order['pay_price'] == $order['refund_price']) { + return $this->fail('已退完支付金额!不能再退款了'); + } + if (!$data['refund_price']) { + return $this->fail('请输入退款金额'); + } + $refund_price = $data['refund_price']; + $data['refund_price'] = bcadd($data['refund_price'], $order['refund_price'], 2); + $bj = bccomp((string)$order['pay_price'], (string)$data['refund_price'], 2); + if ($bj < 0) { + return $this->fail('退款金额大于支付金额,请修改退款金额'); + } + } + if ($data['type'] == 1) { + $data['refund_status'] = 2; + $data['refund_type'] = 6; + } else if ($data['type'] == 2) { + $data['refund_status'] = 0; + $data['refund_type'] = 3; + } + $type = $data['type']; + //拒绝退款 + if ($type == 2) { + $this->services->update((int)$order['id'], ['refund_status' => 0, 'refund_type' => 3]); + return app('json')->successful('修改退款状态成功!'); + } else { + unset($data['type']); + $refund_data['pay_price'] = $order['pay_price']; + $refund_data['refund_price'] = $refund_price; + if ($order['refund_price'] > 0) { + mt_srand(); + $refund_data['refund_id'] = $order['order_id'] . rand(100, 999); + } + + //生成退款订单 + $refundOrderData['uid'] = $order['uid']; + $refundOrderData['store_id'] = $order['store_id']; + $refundOrderData['store_order_id'] = $id; + $refundOrderData['refund_num'] = $order['total_num']; + $refundOrderData['refund_type'] = $data['refund_type']; + $refundOrderData['refund_price'] = $order['pay_price']; + $refundOrderData['refunded_price'] = $refund_price; + $refundOrderData['refund_reason'] = '管理员手动退款'; + $refundOrderData['order_id'] = $storeOrderCreateServices->getNewOrderId(''); + $refundOrderData['refunded_time'] = time(); + $refundOrderData['add_time'] = time(); + $cartInfos = $storeOrderCartInfoServices->getCartColunm(['oid' => $id], 'id,cart_id,cart_num,cart_info'); + foreach ($cartInfos as &$cartInfo) { + $cartInfo['cart_info'] = is_string($cartInfo['cart_info']) ? json_decode($cartInfo['cart_info'], true) : $cartInfo['cart_info']; + } + $refundOrderData['cart_info'] = json_encode(array_column($cartInfos, 'cart_info')); + $res = $services->save($refundOrderData); + + //修改订单退款状态 + if ($services->agreeRefund($res->id, $refund_data)) { + //主动退款清楚原本退款单 + $services->delete(['store_order_id' => $id]); + $this->services->update($id, $data); + return app('json')->success('退款成功'); + } else { + $services->storeProductOrderRefundYFasle((int)$id, $refund_price); + return app('json')->fail('退款失败'); + } + } + } + + /**后台拆单退款 + * @param Request $request + * @param StoreOrderRefundServices $services + * @param StoreOrderCreateServices $storeOrderCreateServices + * @param StoreOrderCartInfoServices $storeOrderCartInfoServices + * @param $id + * @return \think\Response + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function open_order_refund(Request $request, StoreOrderRefundServices $services, $id) + { + $data = $request->postMore([ + ['refund_price', 0], + ['type', 1], + ['is_split_order', 0], + ['cart_ids', []] + ]); + if (!$id) { + return app('json')->fail('Data does not exist!'); + } + $data['refund_price'] = sprintf("%.2f", $data['refund_price']); + $order = $this->services->get($id); + if (!$order) { + return $this->fail('Data does not exist!'); + } + if ($services->count(['store_order_id' => $id, 'refund_type' => [0, 1, 2, 4, 5], 'is_cancel' => 0, 'is_del' => 1])) { + return $this->fail('请先处理售后申请'); + } + //0元退款 + if ($order['pay_price'] == 0 && in_array($order['refund_status'], [0, 1])) { + $refund_price = 0; + } else { + if ($order['pay_price'] == $order['refund_price']) { + return $this->fail('已退完支付金额!不能再退款了'); + } + if (!$data['refund_price']) { + return $this->fail('请输入退款金额'); + } + $refund_price = $data['refund_price']; + $data['refund_price'] = bcadd($data['refund_price'], $order['refund_price'], 2); + $bj = bccomp((string)$order['pay_price'], (string)$data['refund_price'], 2); + if ($bj < 0) { + return $this->fail('退款金额大于支付金额,请修改退款金额'); + } + } + if ($data['type'] == 1) { + $data['refund_status'] = 2; + $data['refund_type'] = 6; + } else if ($data['type'] == 2) { + $data['refund_status'] = 0; + $data['refund_type'] = 3; + } + $type = $data['type']; + if ($data['is_split_order']) { + if (!$data['cart_ids']) { + return app('json')->fail('请选择商品'); + } + foreach ($data['cart_ids'] as $cart) { + if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) { + return app('json')->fail('请重新选择商品,或件数'); + } + } + } + //拒绝退款 + if ($type == 2) { + $this->services->update((int)$order['id'], ['refund_status' => 0, 'refund_type' => 3]); + return app('json')->successful('修改退款状态成功!'); + } else { + unset($data['type']); + $refund_data['pay_price'] = $order['pay_price']; + $refund_data['refund_price'] = $refund_price; + if ($order['refund_price'] > 0) { + mt_srand(); + $refund_data['refund_id'] = $order['order_id'] . rand(100, 999); + } + $refundId = $services->splitApplyRefund((int)$id, $order, $data['cart_ids'], $data['refund_type'], $refund_price, $data); + //修改订单退款状态 + if ($services->agreeRefund($refundId, $refund_data)) { + //主动退款清楚原本退款单 + $services->delete(['store_order_id' => $id]); + if ($data['is_split_order']) { + $services->update($refundId, $data); + } else { + $this->services->update($id, $data); + } + return app('json')->success('退款成功'); + } else { + $services->storeProductOrderRefundYFasle((int)$id, $refund_price); + return app('json')->fail('退款失败'); + } + } + } + + /** + * 订单详情 + * @param $id + * @return mixed + */ + public function order_info($id) + { + if (!$id || !($orderInfo = $this->services->get($id, ['*'], ['invoice', 'virtual', 'pink', 'refund', 'supplierInfo']))) { + return app('json')->fail('订单不存在'); + } + $userInfo = ['spread_uid' => '', 'spread_name' => '无']; + if ($orderInfo['uid']) { + /** @var UserServices $services */ + $services = app()->make(UserServices::class); + $userInfo = $services->getUserWithTrashedInfo($orderInfo['uid']); + if (!$userInfo) return app('json')->fail('用户信息不存在'); + $userInfo = $userInfo->hidden(['pwd', 'add_ip', 'last_ip', 'login_type']); + $userInfo = $userInfo->toArray(); + $userInfo['spread_name'] = '无'; + if ($orderInfo['spread_uid']) { + $spreadName = $services->value(['uid' => $orderInfo['spread_uid']], 'nickname'); + if ($spreadName) { + $userInfo['spread_name'] = $orderInfo['uid'] == $orderInfo['spread_uid'] ? $spreadName . '(自购)' : $spreadName; + $userInfo['spread_uid'] = $orderInfo['spread_uid']; + } else { + $userInfo['spread_uid'] = ''; + } + } else { + $userInfo['spread_uid'] = ''; + } + } + $orderInfo = is_object($orderInfo) ? $orderInfo->toArray() : $orderInfo; + $orderInfo = $this->services->tidyOrder($orderInfo, true, true); + $_status = $orderInfo['_status']; + [$pink_name, $color] = $this->services->tidyOrderType($orderInfo); + $orderInfo['pink_name'] = $pink_name; + $orderInfo['store_order_sn'] = $orderInfo['pid'] ? $this->services->value(['id' => $orderInfo['pid']], 'order_id') : ''; + //核算优惠金额 + $vipTruePrice = 0; + foreach ($orderInfo['cartInfo'] ?? [] as $cart) { + $vipTruePrice = bcadd((string)$vipTruePrice, (string)$cart['vip_sum_truePrice'], 2); + } + $orderInfo['vip_true_price'] = $vipTruePrice; +// $orderInfo['total_price'] = floatval(bcsub((string)$orderInfo['total_price'], (string)$vipTruePrice, 2)); + //优惠活动优惠详情 + /** @var StoreOrderPromotionsServices $storeOrderPromotiosServices */ + $storeOrderPromotiosServices = app()->make(StoreOrderPromotionsServices::class); + $orderInfo['promotions_detail'] = $storeOrderPromotiosServices->getOrderPromotionsDetail((int)$orderInfo['id']); + if ($orderInfo['give_coupon']) { + $couponIds = is_string($orderInfo['give_coupon']) ? explode(',', $orderInfo['give_coupon']) : $orderInfo['give_coupon']; + /** @var StoreCouponIssueServices $couponIssueService */ + $couponIssueService = app()->make(StoreCouponIssueServices::class); + $orderInfo['give_coupon'] = $couponIssueService->getColumn([['id', 'IN', $couponIds]], 'id,coupon_title'); + } + $orderInfo['_store_name'] = ''; + if ($orderInfo['store_id'] && in_array($orderInfo['shipping_type'], [2, 4])) { + /** @var $storeServices */ + $storeServices = app()->make(SystemStoreServices::class); + $orderInfo['_store_name'] = $storeServices->value(['id' => $orderInfo['store_id']], 'name'); + } + + $orderInfo = $this->services->tidyOrderList([$orderInfo])[0]; + $orderInfo['_status_new'] = $orderInfo['_status']; + $orderInfo['_status'] = $_status; + $refund_num = array_sum(array_column($orderInfo['refund'], 'refund_num')); + $cart_num = 0; + foreach ($orderInfo['_info'] as $items) { + if (isset($items['cart_info']['is_gift']) && $items['cart_info']['is_gift']) continue; + $cart_num += $items['cart_info']['cart_num']; + } + $orderInfo['is_all_refund'] = $refund_num == $cart_num; + return app('json')->success(compact('orderInfo', 'userInfo')); + } + + /** + * 查询物流信息 + * @param ExpressServices $services + * @param $id + * @return mixed + */ + public function get_express(ExpressServices $services, $id) + { + if (!$id || !($orderInfo = $this->services->get($id))) + return app('json')->fail('订单不存在'); + if ($orderInfo['delivery_type'] != 'express') + return app('json')->fail('该订单不是快递发货,无法查询物流信息'); + if (!$orderInfo['delivery_id']) + return app('json')->fail('该订单不存在快递单号'); + + $cacheName = $orderInfo['order_id'] . $orderInfo['delivery_id']; + + $data['delivery_name'] = $orderInfo['delivery_name']; + $data['delivery_id'] = $orderInfo['delivery_id']; + $data['result'] = $services->query($cacheName, $orderInfo['delivery_id'], $orderInfo['delivery_code'] ?? null); + return app('json')->success($data); + } + + + /** + * 获取修改配送信息表单结构 + * @param StoreOrderDeliveryServices $services + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function distribution(StoreOrderDeliveryServices $services, $id) + { + if (!$id) { + return app('json')->fail('订单不存在'); + } + return app('json')->success($services->distributionForm((int)$id)); + } + + /** + * 修改配送信息 + * @param StoreOrderDeliveryServices $services + * @param ExpressServices $expressServices + * @param $id + * @return mixed + */ + public function update_distribution(StoreOrderDeliveryServices $services, ExpressServices $expressServices, $id) + { + $data = $this->request->postMore([['delivery_name', ''], ['delivery_id', '']]); + if (!$id) return app('json')->fail('Data does not exist!'); + $orderInfo = $this->services->get((int)$id); + if (!$orderInfo) { + return app('json')->fail('订单不存在'); + } + $express = []; + if ($orderInfo['delivery_type'] == 'express') { + $express = $expressServices->getOne(['name' => $data['delivery_name']], 'id,name,code'); + if (!$express) { + return app('json')->fail('Data does not exist!'); + } + } + $data['delivery_code'] = $express['code']; + $services->updateDistribution($id, $data); + return app('json')->success('Modified success'); + } + + /** + * 不退款表单结构 + * @param StoreOrderRefundServices $services + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function no_refund(StoreOrderRefundServices $services, $id) + { + if (!$id) return app('json')->fail('Data does not exist!'); + return app('json')->success($services->noRefundForm((int)$id)); + } + + /** + * 订单不退款 + * @param StoreOrderRefundServices $services + * @param $id + * @return mixed + */ + public function update_un_refund(StoreOrderRefundServices $services, $id) + { + if (!$id || !($orderRefundInfo = $services->get($id))) + return app('json')->fail('订单不存在'); + [$refund_reason] = $this->request->postMore([['refund_reason', '']], true); + if (!$refund_reason) { + return app('json')->fail('请输入不退款原因'); + } + $refundData = [ + 'refuse_reason' => $refund_reason, + 'refund_type' => 3, + 'refunded_time' => time() + ]; + //拒绝退款处理 + $services->refuseRefund((int)$id, $refundData, $orderRefundInfo); + + return app('json')->success('Modified success'); + } + + /** + * 线下支付 + * @param OrderOfflineServices $services + * @param $id + * @return mixed + */ + public function pay_offline(OrderOfflineServices $services, $id) + { + if (!$id) return app('json')->fail('缺少参数'); + $res = $services->orderOffline((int)$id); + if ($res) { + return app('json')->success('Modified success'); + } else { + return app('json')->fail('Modification failed'); + } + } + + /** + * 退积分表单获取 + * @param StoreOrderRefundServices $services + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function refund_integral(StoreOrderRefundServices $services, $id) + { + if (!$id) + return app('json')->fail('订单不存在'); + return app('json')->success($services->refundIntegralForm((int)$id)); + } + + /** + * 退积分保存 + * @param $id + * @return mixed + */ + public function update_refund_integral(StoreOrderRefundServices $services, $id) + { + [$back_integral] = $this->request->postMore([['back_integral', 0]], true); + if (!$id || !($orderInfo = $this->services->get($id))) { + return app('json')->fail('订单不存在'); + } + if ($orderInfo->is_del) { + return app('json')->fail('订单已删除无法退积分'); + } + if ($back_integral <= 0) { + return app('json')->fail('请输入积分'); + } + if ($orderInfo['use_integral'] == $orderInfo['back_integral']) { + return app('json')->fail('已退完积分!不能再积分了'); + } + + $data['back_integral'] = bcadd((string)$back_integral, (string)$orderInfo['back_integral'], 2); + $bj = bccomp((string)$orderInfo['use_integral'], (string)$data['back_integral'], 2); + if ($bj < 0) { + return app('json')->fail('退积分大于支付积分,请修改退积分'); + } + //积分退款处理 + $orderInfo->back_integral = $data['back_integral']; + if ($services->refundIntegral($orderInfo, $back_integral)) { + return app('json')->success('退积分成功'); + } else { + return app('json')->fail('退积分失败'); + } + } + + /** + * 修改备注 + * @param $id + * @return mixed + */ + public function remark($id) + { + $data = $this->request->postMore([['remark', '']]); + if (!$data['remark']) + return app('json')->fail('请输入要备注的内容'); + if (!$id) + return app('json')->fail('缺少参数'); + + if (!$order = $this->services->get($id)) { + return app('json')->fail('修改的订单不存在!'); + } + $order->remark = $data['remark']; + if ($order->save()) { + return app('json')->success('备注成功'); + } else + return app('json')->fail('备注失败'); + } + + /** + * 获取订单状态列表并分页 + * @param $id + * @return mixed + */ + public function status(StoreOrderStatusServices $services, $id) + { + if (!$id) return app('json')->fail('缺少参数'); + return app('json')->success($services->getStatusList(['oid' => $id])['list']); + } + + /** + * 电子面单模板 + * @param $com + * @return mixed + */ + public function expr_temp(ServeServices $services, $com) + { + if (!$com) { + return app('json')->fail('快递公司编号缺失'); + } + $list = $services->express()->temp($com); + return app('json')->success($list); + } + + /** + * 获取模板 + * @param ServeServices $services + * @return mixed + */ + public function express_temp(ServeServices $services) + { + $data = $this->request->getMore([['com', '']]); + $tpd = $services->express()->temp($data['com']); + return app('json')->success($tpd['data']); + } + + /** + * 订单发货后打印电子面单 + * @param $orderId + * @param StoreOrderDeliveryServices $storeOrderDeliveryServices + * @return mixed + */ + public function order_dump($order_id, StoreOrderDeliveryServices $storeOrderDeliveryServices) + { + return app('json')->success($storeOrderDeliveryServices->orderDump($order_id)); + } + + /**手动批量发货 + * @return \think\Response + * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function hand_batch_delivery() + { + $data = $this->request->getMore([ + ['file', ""] + ]); + if (!$data['file']) return app('json')->fail('请上传文件'); + $file = public_path() . substr($data['file'], 1); + $type = 7;//手动批量发货 + /** @var QueueServices $queueService */ + $queueService = app()->make(QueueServices::class); + $expreData = $this->services->readExpreExcel($file, 2); + $queueId = $queueService->setQueueData([], false, $expreData, $type); + $data['queueType'] = $type; + $data['cacheType'] = 3; + $data['type'] = 1; + $data['queueId'] = $queueId ? $queueId : 0; + $this->services->adminQueueOrderDo($data); + return app('json')->success('后台程序已执行批量发货任务!'); + } + + /** + * 批量手动以外发货 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function other_batch_delivery() + { + $data = $this->request->postMore([ + ['where', []], + ['ids', []], + ['express_record_type', 1], + ['type', 1], + ['delivery_name', ''],//快递公司名称 + ['delivery_id', ''],//快递单号 + ['delivery_code', ''],//快递公司编码 + ['all', 0],//发货记录类型 + ['express_temp_id', ""],//电子面单模板 + ['to_name', ''],//寄件人姓名 + ['to_tel', ''],//寄件人电话 + ['to_addr', ''],//寄件人地址 + + ['sh_delivery_name', ''],//送货人姓名 + ['sh_delivery_id', ''],//送货人电话 + ['sh_delivery_uid', ''],//送货人ID + + ['fictitious_content', '']//虚拟发货内容 + ]); + if ($data['all'] == 0 && empty($data['ids'])) return app('json')->fail('请选择需要发货的订单'); + if ($data['express_record_type'] == 2 && !sys_config('config_export_open', 0)) return app('json')->fail('请先在系统设置中打开单子面单打印开关'); + if ($data['all'] == 1) $data['ids'] = []; + if ($data['type'] == 1) {//批量打印电子面单 + $data['queueType'] = 8; + $data['cacheType'] = 4; + } + if ($data['type'] == 2) {//批量送货 + $data['queueType'] = 9; + $data['cacheType'] = 5; + } + if ($data['type'] == 3) {//批量虚拟 + $data['queueType'] = 10; + $data['cacheType'] = 6; + } + /** @var QueueServices $queueService */ + $queueService = app()->make(QueueServices::class); + $queueId = $queueService->setQueueData($data['where'], 'id', $data['ids'], $data['queueType']); + $data['queueId'] = $queueId ? $queueId : 0; + /** @var StoreOrderDeliveryServices $deliveryService */ + $this->services->adminQueueOrderDo($data); + return app('json')->success('后台程序已执行批量发货任务'); + } + + + /** + * 配货单信息 + * @return mixed + */ + public function distributionInfo() + { + [$ids] = $this->request->postMore([ + ['ids', ''] + ], true); + if (!$ids) { + return app('json')->fail('缺少参数'); + } + $id = explode(',', $ids); + /** @var SupplierOrderServices $supplierOrderServices */ + $supplierOrderServices = app()->make(SupplierOrderServices::class); + $data = $supplierOrderServices->getDistribution($id); + $order = $data[0] ?? []; + if (!$data || !$order) { + return app('json')->fail('获取失败'); + } + $res['list'] = $data; + $station = []; + if ($order['store_id']) {//门店 + /** @var SystemStoreServices $storeServices */ + $storeServices = app()->make(SystemStoreServices::class); + $storeInfo = $storeServices->get($order['store_id']); + $station['site_name'] = $storeInfo['name']; + $station['refund_phone'] = $storeInfo['phone']; + $station['refund_address'] = $storeInfo['detailed_address']; + } elseif ($order['supplier_id']) {//供应商 + /** @var SystemSupplierServices $supplierServices */ + $supplierServices = app()->make(SystemSupplierServices::class); + $supplierIno = $supplierServices->get($order['supplier_id']); + $station['site_name'] = $supplierIno['supplier_name']; + $station['refund_phone'] = $supplierIno['phone']; + $station['refund_address'] = $supplierIno['detailed_address']; + } else {//平台 + $station = SystemConfigService::more(['site_name', 'refund_address', 'refund_phone']); + } + $res = array_merge($res, $station); + return app('json')->success($res); + } + +} diff --git a/app/common/middleware/StationOpenMiddleware.php b/app/common/middleware/StationOpenMiddleware.php index cb99214..86e73ba 100644 --- a/app/common/middleware/StationOpenMiddleware.php +++ b/app/common/middleware/StationOpenMiddleware.php @@ -14,6 +14,7 @@ namespace app\common\middleware; use app\Request; use crmeb\interfaces\MiddlewareInterface; +use think\Response; /** * 站点升级 @@ -22,10 +23,10 @@ use crmeb\interfaces\MiddlewareInterface; */ class StationOpenMiddleware implements MiddlewareInterface { - public function handle(Request $request, \Closure $next) + public function handle(Request $request, \Closure $next): Response { - if (!systemConfig('station_open', true)) { - return app('json')->make('410010', '站点升级中,请稍候访问'); + if (systemConfig('site_open') === '0') { + return app('json')->make(501, '站点已关闭'); } return $next($request); } diff --git a/app/common/middleware/SupplierCheckRoleMiddleware.php b/app/common/middleware/SupplierCheckRoleMiddleware.php index dc5ae1f..6d7681f 100644 --- a/app/common/middleware/SupplierCheckRoleMiddleware.php +++ b/app/common/middleware/SupplierCheckRoleMiddleware.php @@ -17,6 +17,7 @@ use app\services\supplier\LoginServices; use crmeb\exceptions\AuthException; use crmeb\interfaces\MiddlewareInterface; use crmeb\utils\ApiErrorCode; +use think\Response; /** * 权限规则验证 @@ -26,7 +27,7 @@ use crmeb\utils\ApiErrorCode; class SupplierCheckRoleMiddleware implements MiddlewareInterface { - public function handle(Request $request, \Closure $next) + public function handle(Request $request, \Closure $next): Response { if (!$request->supplierId() || !$request->supplierInfo()) throw new AuthException(ApiErrorCode::ERR_ADMINID_VOID); diff --git a/app/common/middleware/SupplierLogMiddleware.php b/app/common/middleware/SupplierLogMiddleware.php index 6652d37..b9c236e 100644 --- a/app/common/middleware/SupplierLogMiddleware.php +++ b/app/common/middleware/SupplierLogMiddleware.php @@ -15,6 +15,7 @@ namespace app\common\middleware; use app\Request; use app\jobs\system\AdminLogJob; use crmeb\interfaces\MiddlewareInterface; +use think\Response; /** * 操作日志记录 @@ -29,7 +30,7 @@ class SupplierLogMiddleware implements MiddlewareInterface * @param \Closure $next * @return mixed */ - public function handle(Request $request, \Closure $next) + public function handle(Request $request, \Closure $next): Response { $module = app('http')->getName(); $rule = trim(strtolower($request->rule()->getRule())); diff --git a/app/controller/store/AuthController.php b/app/controller/store/AuthController.php new file mode 100644 index 0000000..332933b --- /dev/null +++ b/app/controller/store/AuthController.php @@ -0,0 +1,71 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\store; + + +use crmeb\basic\BaseController; + +/** + * 基类 所有控制器继承的类 + * Class AuthController + * @package app\controller\admin + * @method success($msg = 'ok', array $data = []) + * @method fail($msg = 'error', array $data = []) + */ +class AuthController extends BaseController +{ + /** + * 门店整体类型0:平台1:门店2:供应商 + * @var int + */ + protected $type = 1; + /** + * 当前登录门店信息 + * @var + */ + protected $storeInfo; + + /** + * 当前登门店ID + * @var + */ + protected $storeId; + + /** + * 当前登录门店店员ID + * @var + */ + protected $storeStaffId; + /** + * 当前登录门店店员信息 + * @var + */ + protected $storeStaffInfo; + + /** + * 当前管理员权限 + * @var array + */ + protected $auth = []; + + + /** + * 初始化 + */ + protected function initialize() + { + $this->storeId = $this->request->hasMacro('storeId') ? $this->request->storeId() : 0; + $this->storeStaffId = $this->request->hasMacro('storeStaffId') ? $this->request->storeStaffId() : 0; + $this->storeStaffInfo = $this->request->hasMacro('storeStaffInfo') ? $this->request->storeStaffInfo() : []; + $this->auth = $this->storeStaffInfo['rule'] ?? []; + } + +} diff --git a/app/controller/supplier/AuthController.php b/app/controller/supplier/AuthController.php new file mode 100644 index 0000000..02cf07e --- /dev/null +++ b/app/controller/supplier/AuthController.php @@ -0,0 +1,55 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier; + + +use crmeb\basic\BaseController; + +/** + * 基类 所有控制器继承的类 + * Class AuthController + * @package app\controller\admin + * @method success($msg = 'ok', array $data = []) + * @method fail($msg = 'error', array $data = []) + */ +class AuthController extends BaseController +{ + + /** + * 当前登录供应商ID + * @var + */ + protected $supplierId; + + /** + * 当前登录供应商信息 + * @var + */ + protected $supplierInfo; + + /** + * 当前管理员权限 + * @var array + */ + protected $auth = []; + + + /** + * 初始化 + */ + protected function initialize() + { + $this->supplierId = $this->request->hasMacro('supplierId') ? $this->request->supplierId() : 0; + $this->supplierInfo = $this->request->hasMacro('supplierInfo') ? $this->request->supplierInfo() : []; + $this->auth = $this->supplierInfo['rule'] ?? []; + } + +} diff --git a/app/controller/supplier/Common.php b/app/controller/supplier/Common.php new file mode 100644 index 0000000..d1aa826 --- /dev/null +++ b/app/controller/supplier/Common.php @@ -0,0 +1,264 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier; + +use app\services\order\StoreOrderRefundServices; +use app\services\order\StoreOrderServices; +use app\services\other\CityAreaServices; +use app\services\order\supplier\SupplierOrderServices; +use app\services\supplier\SystemSupplierServices; +use app\services\system\SystemMenusServices; + +/** + * 公共接口基类 主要存放公共接口 + * Class Common + * @package app\controller\admin + */ +class Common extends AuthController +{ + /** + * 获取logo + * @param SystemSupplierServices $supplierServices + * @return mixed + */ + public function getLogo(SystemSupplierServices $supplierServices) + { + $supplier = $supplierServices->get((int)$this->supplierId, ['id', 'name']); + return $this->success([ + 'logo' => sys_config('site_logo'), + 'logo_square' => sys_config('site_logo_square'), + 'site_name' => $supplier && isset($supplier['name']) && $supplier['name'] ? $supplier['name'] : sys_config('site_name') + ]); + } + + /** + * @return mixed + */ + public function getConfig() + { + return $this->success([ + 'tengxun_map_key' => sys_config('tengxun_map_key'), + 'open_erp' => !!sys_config('erp_open') + ]); + } + + /** + * 省市区信息 + * @param CityAreaServices $services + * @return mixed + */ + public function city(CityAreaServices $services, $pid = 0) + { + return $this->success($services->getCityTreeList((int)$pid)); + } + + /** + * 格式化菜单 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function menusList() + { + /** @var SystemMenusServices $menusServices */ + $menusServices = app()->make(SystemMenusServices::class); + $list = $menusServices->getSearchList(4); + $counts = $menusServices->getColumn([ + ['type', 3], + ['is_show', '=', 1], + ['auth_type', '=', 1], + ['is_del', '=', 0], + ['is_show_path', '=', 0], + ], 'pid'); + $data = []; + foreach ($list as $key => $item) { + $pid = $item->getData('pid'); + $data[$key] = json_decode($item, true); + $data[$key]['pid'] = $pid; + if (in_array($item->id, $counts)) { + $data[$key]['type'] = 1; + } else { + $data[$key]['type'] = 0; + } + $data[$key]['menu_path'] = preg_replace('/^\/cashier/', '', $item['menu_path']); + } + return $this->success(sort_list_tier($data)); + } + + /** + * 首页运营头部统计 + * @param SupplierOrderServices $orderServices + * @return mixed + */ + public function homeStatics(SupplierOrderServices $orderServices) + { + [$time] = $this->request->getMore([ + ['data', '', '', 'time'] + ], true); + $time = $orderServices->timeHandle($time, true); + $data = $orderServices->homeStatics((int)$this->supplierId, $time); + return $this->success($data); + } + + /** + * 营业趋势图表 + * @param SupplierOrderServices $orderServices + * @return mixed + */ + public function orderChart(SupplierOrderServices $orderServices) + { + [$time] = $this->request->getMore([ + ['data', '', '', 'time'] + ], true); + $time = $orderServices->timeHandle($time, true); + $data = $orderServices->orderCharts((int)$this->supplierId, $time); + return $this->success($data); + } + + /** + * 订单类型分析 + * @param SupplierOrderServices $orderServices + * @return mixed + */ + public function orderType(SupplierOrderServices $orderServices) + { + [$time] = $this->request->getMore([ + ['data', '', '', 'time'] + ], true); + $time = $orderServices->timeHandle($time, true); + $data = $orderServices->getOrderType((int)$this->supplierId, $time); + return $this->success($data); + } + + /** + * 订单来源分析 + * @param SupplierOrderServices $orderServices + * @return mixed + */ + public function orderChannel(SupplierOrderServices $orderServices) + { + [$time] = $this->request->getMore([ + ['data', '', '', 'time'] + ], true); + $time = $orderServices->timeHandle($time, true); + $data = $orderServices->getOrderChannel((int)$this->supplierId, $time); + return $this->success($data); + } + + /** + * 待办事统计 + * @return mixed + */ + public function jnotice() + { + /** @var StoreOrderServices $orderServices */ + $orderServices = app()->make(StoreOrderServices::class); + $orderNum = $orderServices->storeOrderCount((int)$this->supplierId, -1, 'supplier_id'); + /** @var StoreOrderRefundServices $refundServices */ + $refundServices = app()->make(StoreOrderRefundServices::class); + $orderRefundNum = $refundServices->count(['is_cancel' => 0, 'refund_type' => [1, 2, 4, 5], 'supplier_id' => $this->supplierId]); + + $value = []; + if ($orderNum > 0) { + $value[] = [ + 'title' => '您有' . $orderNum . '个待发货的订单', + 'type' => 'bulb', + 'url' => '/' . config('admin.supplier_prefix') . '/order/list?type=7&status=1' + ]; + } + if ($orderRefundNum) { + $value[] = [ + 'title' => '您有' . $orderRefundNum . '个售后订单待处理', + 'type' => 'bulb', + 'url' => '/' . config('admin.supplier_prefix') . '/order/refund' + ]; + } + return $this->success($this->noticeData($value)); + } + + /** + * 消息返回格式 + * @param array $data + * @return array + */ + public function noticeData(array $data): array + { + // 消息图标 + $iconColor = [ + // 邮件 消息 + 'mail' => [ + 'icon' => 'md-mail', + 'color' => '#3391e5' + ], + // 普通 消息 + 'bulb' => [ + 'icon' => 'md-bulb', + 'color' => '#87d068' + ], + // 警告 消息 + 'information' => [ + 'icon' => 'md-information', + 'color' => '#fe5c57' + ], + // 关注 消息 + 'star' => [ + 'icon' => 'md-star', + 'color' => '#ff9900' + ], + // 申请 消息 + 'people' => [ + 'icon' => 'md-people', + 'color' => '#f06292' + ], + ]; + // 消息类型 + $type = array_keys($iconColor); + // 默认数据格式 + $default = [ + 'icon' => 'md-bulb', + 'iconColor' => '#87d068', + 'title' => '', + 'url' => '', + 'type' => 'bulb', + 'read' => 0, + 'time' => 0 + ]; + $value = []; + foreach ($data as $item) { + $val = array_merge($default, $item); + if (isset($item['type']) && in_array($item['type'], $type)) { + $val['type'] = $item['type']; + $val['iconColor'] = $iconColor[$item['type']]['color'] ?? ''; + $val['icon'] = $iconColor[$item['type']]['icon'] ?? ''; + } + $value[] = $val; + } + return $value; + } + + /** + * 获取版权 + * @return mixed + */ + public function getCopyright() + { + try { + $copyright = $this->__z6uxyJQ4xYa5ee1mx5(); + } catch (\Throwable $e) { + $copyright = ['copyrightContext' => '', 'copyrightImage' => '']; + } + $copyright['version'] = get_crmeb_version(); + $copyright['extract_min_price'] = sys_config('supplier_extract_min_price'); + $copyright['extract_max_price'] = sys_config('supplier_extract_max_price'); + return $this->success($copyright); + } +} diff --git a/app/controller/supplier/Login.php b/app/controller/supplier/Login.php new file mode 100644 index 0000000..d648948 --- /dev/null +++ b/app/controller/supplier/Login.php @@ -0,0 +1,194 @@ + +// +---------------------------------------------------------------------- + +namespace app\controller\supplier; + +use app\Request; + +use crmeb\utils\Captcha; +use crmeb\services\CacheService; +use app\services\supplier\LoginServices; +use think\exception\ValidateException; +use app\validate\api\user\RegisterValidates; +use think\facade\Cache; +use think\facade\Config; + +/** + * 登录 + * Class AuthController + * @package app\api\controller + */ +class Login +{ + + /** + * @var LoginServices|null + */ + protected $services = NUll; + + /** + * LoginController constructor. + * @param LoginServices $services + */ + public function __construct(LoginServices $services) + { + $this->services = $services; + } + + /** + * @param Request $request + * @return mixed + * @author 等风来 + * @email 136327134@qq.com + * @date 2022/10/11 + */ + public function getAjCaptcha(Request $request) + { + [$account,] = $request->postMore([ + 'account', + ], true); + + $key = 'supplier_login_captcha_' . $account; + + return app('json')->success(['is_captcha' => Cache::get($key) > 2]); + } + + /** + * @return mixed + */ + public function ajcaptcha(Request $request) + { + $captchaType = $request->get('captchaType'); + return app('json')->success(aj_captcha_create($captchaType)); + } + + /** + * 一次验证 + * @return mixed + */ + public function ajcheck(Request $request) + { + [$token, $pointJson, $captchaType] = $request->postMore([ + ['token', ''], + ['pointJson', ''], + ['captchaType', ''], + ], true); + try { + aj_captcha_check_one($captchaType, $token, $pointJson); + return app('json')->success(); + } catch (\Throwable $e) { + return app('json')->fail(400336); + } + } + + /** + * 获取后台登录页轮播图以及LOGO + * @return mixed + */ + public function info() + { + return app('json')->success($this->services->getLoginInfo()); + } + + /** + * 验证码 + * @return \app\controller\admin\Login|\think\Response + */ + public function captcha() + { + return app()->make(Captcha::class)->create(); + } + + /** + * H5账号登陆 + * @param Request $request + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function login(Request $request) + { + [$account, $password, $captchaType, $captchaVerification] = $request->postMore([ + 'account', + 'pwd', + ['captchaType', ''], + ['captchaVerification', ''] + ], true); + + validate(\app\validate\supplier\SystemSupplierValidate::class)->scene('login')->check(['account' => $account, 'pwd' => $password]); + + $key = 'supplier_login_captcha_' . $account; + + if (Cache::has($key) && Cache::get($key) > 2) { + if (!$captchaType || !$captchaVerification) { + return app('json')->fail('请拖动滑块验证'); + } + //二次验证 + try { + aj_captcha_check_two($captchaType, $captchaVerification); + } catch (\Throwable $e) { + return app('json')->fail($e->getError()); + } + } + $res = $this->services->login($account, $password, 'supplier'); + if ($res) { + Cache::delete($key); + } + return app('json')->success($res); + } + + /** + * 退出登录 + * @param Request $request + * @return mixed + * @throws \Psr\SimpleCache\InvalidArgumentException + */ + public function logout(Request $request) + { + $key = trim(ltrim($request->header(Config::get('cookie.token_name')), 'Bearer')); + CacheService::redisHandler()->delete(md5($key)); + return app('json')->success(); + } + + /** + * 密码修改 + * @param Request $request + * @return mixed + */ + public function reset(Request $request) + { + [$account, $captcha, $password] = $request->postMore([['account', ''], ['captcha', ''], ['password', '']], true); + try { + validate(RegisterValidates::class)->scene('register')->check(['account' => $account, 'captcha' => $captcha, 'password' => $password]); + } catch (ValidateException $e) { + return app('json')->fail($e->getError()); + } + $verifyCode = CacheService::get('code_' . $account); + if (!$verifyCode) + return app('json')->fail('请先获取验证码'); + $verifyCode = substr($verifyCode, 0, 6); + if ($verifyCode != $captcha) { + return app('json')->fail('验证码错误'); + } + if (strlen(trim($password)) < 4 || strlen(trim($password)) > 64) + return app('json')->fail('密码必须是在4到64位之间'); + if ($password == '123456') return app('json')->fail('密码太过简单,请输入较为复杂的密码'); + $resetStatus = $this->services->reset($account, $password); + if ($resetStatus) { + CacheService::delete('code_' . $account); + return app('json')->success('修改成功'); + } + return app('json')->fail('修改失败'); + } + + +} diff --git a/app/controller/supplier/Order.php b/app/controller/supplier/Order.php new file mode 100644 index 0000000..04451f4 --- /dev/null +++ b/app/controller/supplier/Order.php @@ -0,0 +1,222 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier; + +use app\common\controller\Order as CommonOrder; +use app\Request; +use app\services\order\StoreOrderDeliveryServices; +use app\services\order\StoreOrderServices; +use app\services\store\DeliveryServiceServices; +use app\services\order\supplier\SupplierOrderServices; +use think\facade\App; + +/** + * Class Order + * @package app\controller\supplier + * @property Request $request + */ +class Order extends AuthController +{ + + use CommonOrder; + + protected $orderServices; + + /** + * Order constructor. + * @param App $app + * @param SupplierOrderServices $service + * @param StoreOrderServices $orderServices + */ + public function __construct(App $app, SupplierOrderServices $supplierOrderServices, StoreOrderServices $services) + { + parent::__construct($app); + $this->services = $services; + $this->supplierOrderServices = $supplierOrderServices; + } + + /** + * 获取订单列表 + * @param Request $request + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function lst(Request $request) + { + $where = $request->getMore([ + ['status', ''], + ['real_name', ''], + ['is_del', ''], + ['data', '', '', 'time'], + ['type', ''], + ['pay_type', ''], + ['order', ''], + ['field_key', ''], + ]); + $where['type'] = trim($where['type']); + $where['is_system_del'] = 0; + if (!$where['real_name'] && !in_array($where['status'], [-1, -2, -3])) { + $where['pid'] = 0; + } + $where['supplier_id'] = $this->supplierId; + return $this->success($this->services->getOrderList($where, ['*'], ['split' => function ($query) { + $query->field('id,pid'); + }, 'pink', 'invoice'])); + } + + /** + *获取所有配送员列表 + */ + public function get_delivery_list() + { + /** @var DeliveryServiceServices $deliverServices */ + $deliverServices = app()->make(DeliveryServiceServices::class); + $data = $deliverServices->getDeliveryList(2, (int)$this->supplierId); + return $this->success($data); + } + + /** + * 订单发送货 + * @param Request $request + * @param StoreOrderDeliveryServices $services + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function update_delivery(Request $request, StoreOrderDeliveryServices $services, $id) + { + $data = $request->postMore([ + ['type', 1], + ['delivery_name', ''],//快递公司名称 + ['delivery_id', ''],//快递单号 + ['delivery_code', ''],//快递公司编码 + + ['express_record_type', 2],//发货记录类型 + ['express_temp_id', ""],//电子面单模板 + ['to_name', ''],//寄件人姓名 + ['to_tel', ''],//寄件人电话 + ['to_addr', ''],//寄件人地址 + + ['sh_delivery_name', ''],//送货人姓名 + ['sh_delivery_id', ''],//送货人电话 + ['sh_delivery_uid', ''],//送货人ID + ['delivery_type', 1],//送货类型 + ['station_type', 1],//送货类型 + ['cargo_weight', 0],//重量 + ['mark', '', '', 'remark'],//管理员备注 + ['remark', '', '', 'delivery_remark'],//第三方配送备注 + + ['fictitious_content', '']//虚拟发货内容 + ]); + if (!$id) { + return app('json')->fail('缺少发货ID'); + } + $services->setItem('supplier_id', $this->supplierId); + $res = $services->delivery((int)$id, $data); + $services->reset(); + return app('json')->success('SUCCESS', $res); + } + + /** + * 订单拆单发送货 + * @param Request $request + * @param StoreOrderDeliveryServices $services + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function split_delivery(Request $request, StoreOrderDeliveryServices $services, $id) + { + $data = $request->postMore([ + ['type', 1], + ['delivery_name', ''],//快递公司名称 + ['delivery_id', ''],//快递单号 + ['delivery_code', ''],//快递公司编码 + + ['express_record_type', 2],//发货记录类型 + ['express_temp_id', ""],//电子面单模板 + ['to_name', ''],//寄件人姓名 + ['to_tel', ''],//寄件人电话 + ['to_addr', ''],//寄件人地址 + + ['sh_delivery_name', ''],//送货人姓名 + ['sh_delivery_id', ''],//送货人电话 + ['sh_delivery_uid', ''],//送货人ID + ['delivery_type', 1],//送货类型 + ['station_type', 1],//送货类型 + ['cargo_weight', 0],//重量 + ['mark', ''],//备注 + ['remark', ''],//配送备注 + + ['fictitious_content', ''],//虚拟发货内容 + + ['cart_ids', []] + ]); + if (!$id) { + return app('json')->fail('缺少发货ID'); + } + if (!$data['cart_ids']) { + return app('json')->fail('请选择发货商品'); + } + foreach ($data['cart_ids'] as $cart) { + if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) { + return app('json')->fail('请重新选择发货商品,或发货件数'); + } + } + $services->setItem('supplier_id', $this->supplierId); + $services->splitDelivery((int)$id, $data); + $services->reset(); + return app('json')->success('SUCCESS'); + } + + + /** + * 获取订单拆分子订单列表 + * @return mixed + */ + public function split_order(Request $request, $id) + { + if (!$id) { + return app('json')->fail('缺少订单ID'); + } + $where = ['pid' => $id, 'is_system_del' => 0, 'supplier_id' => $this->supplierId]; + if (!$this->services->count($where)) { + $where = ['id' => $id, 'is_system_del' => 0, 'supplier_id' => $this->supplierId]; + } + return app('json')->success($this->services->getSplitOrderList($where, ['*'], ['split', 'pink', 'invoice', 'supplier'])); + } + + /** + * 易联云打印机打印 + * @param $id + * @return mixed + */ + public function order_print($id) + { + if (!$id) return app('json')->fail('缺少参数'); + $order = $this->services->get($id); + if (!$order) { + return app('json')->fail('订单没有查到,无法打印!'); + } + $res = $this->services->orderPrint((int)$id, 2, (int)$this->supplierId); + if ($res) { + return app('json')->success('打印成功'); + } else { + return app('json')->fail('打印失败'); + } + } +} diff --git a/app/controller/supplier/Refund.php b/app/controller/supplier/Refund.php new file mode 100644 index 0000000..4a2a088 --- /dev/null +++ b/app/controller/supplier/Refund.php @@ -0,0 +1,222 @@ + +// +---------------------------------------------------------------------- + +namespace app\controller\supplier; + + +use app\Request; +use app\services\order\StoreOrderRefundServices; +use app\services\order\StoreOrderServices; +use app\services\user\UserServices; +use think\facade\App; + +/** + * Class Refund + * @package app\controller\supplier + */ +class Refund extends AuthController +{ + /** + * StoreOrder constructor. + * @param App $app + * @param StoreOrderRefundServices $service + * @method temp + */ + public function __construct(App $app, StoreOrderRefundServices $service) + { + parent::__construct($app); + $this->services = $service; + } + + /** + * 退款订单列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getRefundList() + { + $where = $this->request->getMore([ + ['order_id', ''], + ['time', ''], + ['refund_type', 0] + ]); + $where['supplier_id'] = $this->supplierId; + return $this->success($this->services->refundList($where)); + } + + /** + * 订单详情 + * @param UserServices $userServices + * @param $id + * @return mixed + */ + public function detail(UserServices $userServices, $id) + { + $order = $this->services->refundDetail($id); + $order['total_price'] = floatval(bcadd((string)$order['total_price'], (string)$order['vip_true_price'], 2)); + $data['orderInfo'] = $order; + $userInfo = ['spread_uid' => '', 'spread_name' => '无']; + if ($order['uid']) { + $userInfo = $userServices->getUserWithTrashedInfo((int)$order['uid']); + if (!$userInfo) return app('json')->fail('用户信息不存在'); + $userInfo = $userInfo->hidden(['pwd', 'add_ip', 'last_ip', 'login_type']); + $userInfo = $userInfo->toArray(); + $userInfo['spread_name'] = '无'; + if ($order['spread_uid']) { + $spreadName = $userServices->value(['uid' => $order['spread_uid']], 'nickname'); + if ($spreadName) { + $userInfo['spread_name'] = $order['uid'] == $order['spread_uid'] ? $spreadName . '(自购)' : $spreadName; + $userInfo['spread_uid'] = $order['spread_uid']; + } else { + $userInfo['spread_uid'] = ''; + } + } else { + $userInfo['spread_uid'] = ''; + } + } + $data['userInfo'] = $userInfo; + return app('json')->successful('ok', $data); + } + + /** + * 退款表单生成 + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function refund($id) + { + if (!$id) { + return app('json')->fail('Data does not exist!'); + } + return app('json')->success($this->services->refundOrderForm((int)$id)); + } + + /** + * 订单退款 + * @param Request $request + * @param StoreOrderServices $services + * @param $id + * @return mixed + */ + public function update_refund(Request $request, StoreOrderServices $services, $id) + { + $data = $request->postMore([ + ['refund_price', 0], + ['type', 1] + ]); + if (!$id) { + return app('json')->fail('Data does not exist!'); + } + $data['refund_price'] = sprintf("%.2f", $data['refund_price']); + $orderRefund = $this->services->get($id); + if (!$orderRefund) { + return app('json')->fail('Data does not exist!'); + } + if ($orderRefund['is_cancel'] == 1) { + return app('json')->fail('用户已取消申请'); + } + $order = $services->get((int)$orderRefund['store_order_id']); + if (!$order) { + return app('json')->fail('Data does not exist!'); + } + if (!in_array($orderRefund['refund_type'], [1, 2, 5])) { + return app('json')->fail('售后订单状态不支持该操作'); + } + + if ($data['type'] == 1) { + $data['refund_type'] = 6; + } else if ($data['type'] == 2) { + $data['refund_type'] = 3; + } + $data['refunded_time'] = time(); + $type = $data['type']; + //拒绝退款 + if ($type == 2) { + $this->services->refuseRefund((int)$orderRefund['id'], $data, $orderRefund); + return app('json')->successful('修改退款状态成功!'); + } else { + //0元退款 + if ($orderRefund['refund_price'] == 0) { + $refund_price = 0; + } else { + if (!$data['refund_price']) { + return app('json')->fail('请输入退款金额'); + } + if ($orderRefund['refund_price'] == $orderRefund['refunded_price']) { + return app('json')->fail('已退完支付金额!不能再退款了'); + } + $refund_price = $data['refund_price']; + + $data['refunded_price'] = bcadd($data['refund_price'], $orderRefund['refunded_price'], 2); + $bj = bccomp((string)$orderRefund['refund_price'], (string)$data['refunded_price'], 2); + if ($bj < 0) { + return app('json')->fail('退款金额大于支付金额,请修改退款金额'); + } + } + + unset($data['type']); + $refund_data['pay_price'] = $order['pay_price']; + $refund_data['refund_price'] = $refund_price; + + //修改订单退款状态 + unset($data['refund_price']); + if ($this->services->agreeRefund($id, $refund_data)) { + //退款处理 + $this->services->update($id, $data); + return app('json')->success('退款成功'); + } else { + $this->services->storeProductOrderRefundYFasle((int)$id, $refund_price); + return app('json')->fail('退款失败'); + } + } + } + + /** + * 商家同意退货退款 + * @return mixed + */ + public function agreeRefund() + { + [$id] = $this->request->getMore([ + ['order_id', ''] + ], true); + $this->services->agreeRefundProdcut((int)$id); + return app('json')->success('操作成功'); + } + + /** + * 修改备注 + * @param $id + * @return mixed + */ + public function remark($id) + { + $data = $this->request->postMore([['remark', '']]); + if (!$data['remark']) + return app('json')->fail('请输入要备注的内容'); + if (!$id) + return app('json')->fail('缺少参数'); + + if (!$order = $this->services->get($id)) { + return app('json')->fail('修改的订单不存在!'); + } + $order->remark = $data['remark']; + if ($order->save()) { + return app('json')->success('备注成功'); + } else + return app('json')->fail('备注失败'); + } + +} + diff --git a/app/controller/supplier/export/ExportExcel.php b/app/controller/supplier/export/ExportExcel.php new file mode 100644 index 0000000..f17f952 --- /dev/null +++ b/app/controller/supplier/export/ExportExcel.php @@ -0,0 +1,140 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\export; + +use app\controller\supplier\AuthController; +use app\services\other\export\ExportServices; +use app\services\order\StoreOrderServices; +use app\services\other\ExpressServices; +use app\services\other\queue\QueueAuxiliaryServices; +use app\services\other\queue\QueueServices; +use app\services\supplier\finance\SupplierFlowingWaterServices; +use think\facade\App; + +/** + * 导出excel类 + * Class ExportExcel + * @package app\controller\supplier\export + */ +class ExportExcel extends AuthController +{ + /** + * @var ExportServices + */ + protected $service; + + /** + * ExportExcel constructor. + * @param App $app + * @param ExportServices $services + */ + public function __construct(App $app, ExportServices $services) + { + parent::__construct($app); + $this->service = $services; + } + + /** + * 订单列表导出 + * @param StoreOrderServices $services + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function storeOrder(StoreOrderServices $services) + { + $where_tmp = $this->request->getMore([ + ['status', ''], + ['real_name', ''], + ['data', '', '', 'time'], + ['type', ''], + ['ids', ''] + ]); + $type = $where_tmp['type']; + $with = []; + if ($where_tmp['ids']) { + $where['id'] = explode(',', $where_tmp['ids']); + } + if ($type) { + $where['status'] = 1; + $where['paid'] = 1; + $where['is_del'] = 0; + $where['is_system_del'] = 0; + $with = ['pink', 'refund' => function ($query) { + $query->whereIn('refund_type', [1, 2, 4, 5])->where('is_cancel', 0)->where('is_del', 0)->field('id,store_order_id'); + }]; + } + if (!$where_tmp['ids'] && !$type) { + unset($where_tmp['ids']); + unset($where_tmp['type']); + $where = $where_tmp; + } + if (!$where_tmp['real_name'] && !in_array($where_tmp['status'], [-1, -2, -3])) { + $where['pid'] = 0; + } + $where['is_system_del'] = 0; + $where['supplier_id'] = $this->supplierId; + $data = $services->getExportList($where, $with, $this->service->limit); + return $this->success($this->service->storeOrder($data, $type)); + } + + /** + * 导出批量任务发货的记录 + * @param int $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function batchOrderDelivery($id, $queueType, $cacheType) + { + /** @var QueueAuxiliaryServices $auxiliaryService */ + $auxiliaryService = app()->make(QueueAuxiliaryServices::class); + /** @var QueueServices $queueService */ + $queueService = app()->make(QueueServices::class); + $queueInfo = $queueService->getQueueOne(['id' => $id]); + if (!$queueInfo) return $this->fail("数据不存在"); + $queueValue = json_decode($queueInfo['queue_in_value'], true); + if (!$queueValue || !isset($queueValue['cacheType'])) return $this->fail("数据参数缺失"); + $data = $auxiliaryService->getExportData(['binding_id' => $id, 'type' => $cacheType], $this->service->limit); + return $this->success($this->service->batchOrderDelivery($data, $queueType)); + } + + /** + * 物流公司表导出 + * @return mixed + */ + public function expressList() + { + /** @var ExpressServices $expressService */ + $expressService = app()->make(ExpressServices::class); + $data = $expressService->apiExpressList(); + return $this->success($this->service->expressList($data)); + } + + /** + * 供应商账单下载 + * @param SupplierFlowingWaterServices $services + * @return mixed + */ + public function financeRecord(SupplierFlowingWaterServices $services) + { + [$ids] = $this->request->getMore([ + ['ids', ''] + ], true); + $where['id'] = $ids ? explode(',', $ids) : []; + $where['is_del'] = 0; + $where['supplier_id'] = $this->supplierId; + $data = $services->getList($where); + return $this->success($this->service->SupplierFinanceRecord($data['list'] ?? [])); + } +} diff --git a/app/controller/supplier/file/SystemAttachment.php b/app/controller/supplier/file/SystemAttachment.php new file mode 100644 index 0000000..f8ca259 --- /dev/null +++ b/app/controller/supplier/file/SystemAttachment.php @@ -0,0 +1,231 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\file; + +use app\controller\supplier\AuthController; +use app\services\other\CacheServices; +use app\services\system\admin\SystemAdminServices; +use app\services\system\attachment\SystemAttachmentServices; +use think\facade\App; + +/** + * 图片管理类 + * Class SystemAttachment + * @package app\controller\store\file + */ +class SystemAttachment extends AuthController +{ + protected $service; + + public function __construct(App $app, SystemAttachmentServices $service) + { + parent::__construct($app); + $this->service = $service; + } + + /** + * 显示列表 + * @return mixed + */ + public function index() + { + $where = $this->request->getMore([ + ['pid', 0], + ['file_type', 1] + ]); + $where['type'] = 4; + $where['relation_id'] = $this->supplierId; + return app('json')->success($this->service->getImageList($where)); + } + + /** + * 删除指定资源 + * + * @param string $ids + * @return \think\Response + */ + public function delete() + { + [$ids] = $this->request->postMore([ + ['ids', ''] + ], true); + $this->service->del($ids); + return app('json')->success('删除成功'); + } + + /** + * 图片上传 + * @param int $upload_type + * @param int $type + * @return mixed + */ + public function upload($upload_type = 0, $type = 0) + { + [$pid, $file] = $this->request->postMore([ + ['pid', 0], + ['file', 'file'], + ], true); + $res = $this->service->storeUpload((int)$pid, $file, (int)$this->supplierId, 4); + return app('json')->success('上传成功', ['src' => $res]); + } + + /** + * 移动图片 + * @return mixed + */ + public function moveImageCate() + { + $data = $this->request->postMore([ + ['pid', 0], + ['images', ''] + ]); + $this->service->move($data); + return app('json')->success('移动成功'); + } + + /** + * 修改文件名 + * @param $id + * @return mixed + */ + public function update($id) + { + $realName = $this->request->post('real_name', ''); + if (!$realName) { + return app('json')->fail('文件名称不能为空'); + } + $this->service->update($id, ['real_name' => $realName]); + return app('json')->success('修改成功'); + } + + /** + * 获取上传类型 + * @return mixed + */ + public function uploadType() + { + $data['upload_type'] = (string)sys_config('upload_type', 1); + return app('json')->success($data); + } + + /** + * 视频分片上传 + * @return mixed + */ + public function videoUpload() + { + $data = $this->request->postMore([ + ['chunkNumber', 0],//第几分片 + ['currentChunkSize', 0],//分片大小 + ['chunkSize', 0],//总大小 + ['totalChunks', 0],//分片总数 + ['file', 'file'],//文件 + ['md5', ''],//MD5 + ['filename', ''],//文件名称 + ['pid', 0],//分类ID + ]); + $fileHandle = $this->request->file($data['file']); + if (!$fileHandle) return $this->fail('上传信息为空'); + $res = $this->service->videoUpload($data, $fileHandle, 4, (int)$this->supplierId); + return app('json')->success($res); + } + + /** + * 保存云端视频记录 + * @return mixed + */ + public function saveVideoAttachment() + { + $data = $this->request->postMore([ + ['path', ''],//视频地址 + ['cover_image', ''],//封面地址 + ['pid', 0],//分类ID + ['upload_type', 1],//上传类型 + ]); + $res = $this->service->saveOssVideoAttachment($data, 4, (int)$this->supplierId, (int)$data['upload_type']); + return app('json')->success($res); + } + + /**获取扫码上传页面链接以及参数 + * @return \think\Response + */ + public function scanUploadQrcode(CacheServices $services) + { + [$pid] = $this->request->getMore([ + ['pid', 0] + ], true); + $uploadToken = md5(time()); + $upload_file_size_max = config('upload.filesize');//文件上传大小kb + $services->setDbCache($this->supplierId.'_supplier_scan_upload', $uploadToken, 68400); + $url = sys_config('site_url') . '/app/upload?pid=' . $pid . '&cache='. $this->supplierId .'_supplier_scan_upload&type=4&relation_id='. $this->supplierId . '&upload_file_size_max=' . $upload_file_size_max . '&token=' . $uploadToken; + return app('json')->success(['url' => $url]); + } + + /**删除二维码 + * @return \think\Response + */ + public function removeUploadQrcode(CacheServices $services) + { + $services->delectDbCache($this->supplierId.'_supplier_scan_upload'); + return app('json')->success(); + } + + /**获取扫码上传的图片数据 + * @param $scan_token + * @return \think\Response + */ + public function scanUploadImage($scan_token) + { + return app('json')->success($this->service->scanUploadImage($scan_token)); + } + + /**网络图片上传 + * @return \think\Response + */ + public function onlineUpload() + { + $data = $this->request->postMore([ + ['pid', 0], + ['images', []] + ]); + $this->service->onlineUpload($data,4,(int)$this->supplierId); + return app('json')->success('上传完成'); + } + + /**获取上传信息 + * @return \think\Response + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getAdminsData() + { + /** @var SystemAdminServices $adminServices */ + $adminServices = app()->make(SystemAdminServices::class); + $data['is_way'] = $adminServices->value(['id'=>$this->supplierId], 'is_way'); + $data['upload_file_size_max'] = config('upload.filesize');//文件上传大小kb + return app('json')->success($data); + } + + /**保存上传信息 + * @param int $is_way + * @return \think\Response + */ + public function setAdminsData(int $is_way = 0) + { + /** @var SystemAdminServices $adminServices */ + $adminServices = app()->make(SystemAdminServices::class); + if(!in_array($is_way,[0,1,2])) return app('json')->fail('参数有误!'); + $res = $adminServices->update($this->supplierId, ['is_way' => $is_way]); + if($res) return app('json')->success('ok'); + else return app('json')->fail('保存失败'); + } +} diff --git a/app/controller/supplier/file/SystemAttachmentCategory.php b/app/controller/supplier/file/SystemAttachmentCategory.php new file mode 100644 index 0000000..71952ee --- /dev/null +++ b/app/controller/supplier/file/SystemAttachmentCategory.php @@ -0,0 +1,134 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\file; + +use app\controller\supplier\AuthController; +use app\services\system\attachment\SystemAttachmentCategoryServices; +use think\facade\App; + +/** + * 图片分类管理类 + * Class SystemAttachmentCategory + * @package app\controller\supplier\file + */ +class SystemAttachmentCategory extends AuthController +{ + + protected $service; + + public function __construct(App $app, SystemAttachmentCategoryServices $service) + { + parent::__construct($app); + $this->service = $service; + } + + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index() + { + $where = $this->request->getMore([ + ['name', ''], + ['pid', 0], + ['file_type', 1] + ]); + $where['type'] = 4; + $where['relation_id'] = $this->supplierId; + if ($where['name'] != '') $where['pid'] = ''; + return app('json')->success($this->service->getAll($where)); + } + + /** + * 新增表单 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function create($id) + { + [$file_type] = $this->request->postMore([ + ['file_type', 1] + ], true); + return app('json')->success($this->service->createForm($id, 4, $this->supplierId, (int)$file_type)); + } + + /** + * 保存新增 + * @return mixed + */ + public function save() + { + $data = $this->request->postMore([ + ['pid', 0], + ['name', ''], + ['file_type', 1] + ]); + if (!$data['name']) { + return app('json')->fail('请输入分类名称'); + } + $data['type'] = 4; + $data['relation_id'] = $this->supplierId; + $this->service->save($data); + return app('json')->success('添加成功'); + } + + /** + * 编辑表单 + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id) + { + [$file_type] = $this->request->postMore([ + ['file_type', 1] + ], true); + return app('json')->success($this->service->editForm($id, 4, $this->supplierId, (int)$file_type)); + } + + /** + * 保存更新的资源 + * + * @param \think\Request $request + * @param int $id + * @return \think\Response + */ + public function update($id) + { + $data = $this->request->postMore([ + ['pid', 0], + ['name', ''], + ['file_type', 1] + ]); + if (!$data['name']) { + return app('json')->fail('请输入分类名称'); + } + $info = $this->service->get($id); + $data['relation_id'] = $this->supplierId; + $count = $this->service->count(['pid' => $id]); + if ($count && $info['pid'] != $data['pid']) return app('json')->fail('该分类有下级分类,无法修改上级'); + $this->service->update($id, $data); + return app('json')->success('分类编辑成功!'); + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + $this->service->del($id); + return app('json')->success('删除成功!'); + } +} diff --git a/app/controller/supplier/finance/SupplierExtract.php b/app/controller/supplier/finance/SupplierExtract.php new file mode 100644 index 0000000..d47191b --- /dev/null +++ b/app/controller/supplier/finance/SupplierExtract.php @@ -0,0 +1,131 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\finance; + + +use app\services\supplier\finance\SupplierFlowingWaterServices; +use think\exception\ValidateException; +use think\facade\App; +use think\facade\Config; +use app\controller\supplier\AuthController; +use app\services\supplier\finance\SupplierExtractServices; + + +/** + * 供应商提现 + * Class SupplierExtract + * @package app\controller\supplier\finance + */ +class SupplierExtract extends AuthController +{ + /** + * StoreExtract constructor. + * @param App $app + * @param SupplierExtractServices $services + */ + public function __construct(App $app, SupplierExtractServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + + /** + * 显示资源列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function index() + { + $where = $this->request->getMore([ + ['status', ''], + ['pay_status', ''], + ['extract_type', ''], + ['nireid', '', '', 'like'], + ['data', '', '', 'time'], + ]); + if (isset($where['extract_type']) && $where['extract_type'] == 'wx') { + $where['extract_type'] = 'weixin'; + } + $where['supplier_id'] = $this->supplierId; + $whereData = [ + 'supplier_id' => $this->supplierId, + 'is_del' => 0, + ]; + return app('json')->success($this->services->index($where,$whereData)); + } + + /** + * 增加备注 + * @param $id + * @return mixed + */ + public function mark($id) + { + [$mark] = $this->request->getMore([ + ['mark', ''] + ], true); + if (!$id || !$mark) { + return app('json')->fail('缺少参数'); + } + $extract = $this->services->get((int)$id); + if (!$extract) { + return app('json')->fail('转账记录不存在'); + } + if (!$this->services->update($id, ['supplier_mark' => $mark])) { + return app('json')->fail('备注失败'); + } + return app('json')->success('备注成功'); + } + + /** + * 提现申请 + * @param Request $request + * @return mixed + */ + public function cash() + { + $extractInfo = $this->request->postMore([ + ['extract_type', ''], + ['money', 0], + ['mark', ''] + ]); + $extractType = Config::get('pay.extractType', []); + //最低提现 + $supplier_extract_min_price = sys_config('supplier_extract_min_price') ?? 0; + //最高提现 + $supplier_extract_max_price = sys_config('supplier_extract_max_price') ?? 0; + if ($extractInfo['money'] < $supplier_extract_min_price) + return app('json')->fail('最低提现' . $supplier_extract_min_price . '元'); + if ($extractInfo['money'] > $supplier_extract_max_price) + return app('json')->fail('最高提现' . $supplier_extract_max_price . '元'); + //可提现金额 + /** @var SupplierFlowingWaterServices $financeFlowServices */ + $financeFlowServices = app()->make(SupplierFlowingWaterServices::class); + $whereData = [ + 'supplier_id' => $this->supplierId, + 'is_del' => 0, + ]; + $price_not = $financeFlowServices->getSumFinance(['supplier_id' => $this->supplierId], $whereData); + if ($extractInfo['money'] > $price_not) { + throw new ValidateException($price_not > 0 ? '可提现金额为' . $price_not . '元': '暂无可提现金额'); + } + if (!in_array($extractInfo['extract_type'], $extractType)) + return app('json')->fail('转账方式不存在'); + if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', (float)$extractInfo['money'])) return app('json')->fail('转账金额输入有误'); + if ($this->services->cash((int)$this->supplierId, $extractInfo)) + return app('json')->successful('申请转账成功!'); + else + return app('json')->fail('转账失败'); + } +} diff --git a/app/controller/supplier/finance/SupplierFlowingWater.php b/app/controller/supplier/finance/SupplierFlowingWater.php new file mode 100644 index 0000000..79267bd --- /dev/null +++ b/app/controller/supplier/finance/SupplierFlowingWater.php @@ -0,0 +1,122 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\finance; + + +use app\services\supplier\finance\SupplierFlowingWaterServices; +use think\facade\App; +use app\controller\supplier\AuthController; + + +/** + * 供应商流水 + * Class SupplierFlowingWater + * @package app\controller\supplier\finance + */ +class SupplierFlowingWater extends AuthController +{ + /** + * SupplierFlowingWater constructor. + * @param App $app + * @param SupplierFlowingWaterServices $services + */ + public function __construct(App $app, SupplierFlowingWaterServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + + /** + * 显示资源列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function index() + { + $where = $this->request->getMore([ + ['type', ''], + ['data', '', '', 'time'], + ]); + $where['keyword'] = $this->request->param('keyword', ''); + $where['supplier_id'] = $this->supplierId; + $where['is_del'] = 0; + return app('json')->success($this->services->getList($where)); + } + + /** + * 增加备注 + * @param $id + * @return mixed + */ + public function mark($id) + { + [$mark] = $this->request->postMore([ + ['mark', ''] + ], true); + if (!$id || !$mark) { + return app('json')->fail('缺少参数'); + } + $info = $this->services->get((int)$id); + if (!$info) { + return app('json')->fail('流水不存在'); + } + if (!$this->services->update($id, ['mark' => $mark])) { + return app('json')->fail('备注失败'); + } + return app('json')->success('备注成功'); + } + + /**获取交易类型 + * @return \think\Response + */ + public function getType() + { + return app('json')->success($this->services->type); + } + + /** + * 账单记录 + * @return mixed + */ + public function fundRecord() + { + $where = $this->request->getMore([ + ['timeType', 'day'], + ['data', '', '', 'time'], + ]); + $where['supplier_id'] = $this->supplierId; + return app('json')->success($this->services->getFundRecord($where)); + } + + /** + * 账单详情 + * @param $ids + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function fundRecordInfo() + { + $where = $this->request->getMore([ + ['ids', ''] + ]); + $where['keyword'] = $this->request->param('keyword', ''); + $where['id'] = $where['ids'] ? explode(',', $where['ids']) : []; + unset($where['ids']); + $where['is_del'] = 0; + $where['supplier_id'] = $this->supplierId; + return app('json')->success($this->services->getList($where)); + } +} diff --git a/app/controller/supplier/finance/SupplierTransactions.php b/app/controller/supplier/finance/SupplierTransactions.php new file mode 100644 index 0000000..c92d0cd --- /dev/null +++ b/app/controller/supplier/finance/SupplierTransactions.php @@ -0,0 +1,37 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\finance; + + +use app\services\supplier\finance\SupplierTransactionsServices; +use think\facade\App; +use app\controller\supplier\AuthController; + + +/** + * 供应商交易 + * Class SupplierTransactions + * @package app\controller\supplier\finance + */ +class SupplierTransactions extends AuthController +{ + /** + * StoreFinanceFlow constructor. + * @param App $app + * @param SupplierTransactionsServices $services + */ + public function __construct(App $app, SupplierTransactionsServices $services) + { + parent::__construct($app); + $this->services = $services; + } + +} diff --git a/app/controller/supplier/product/StoreBrand.php b/app/controller/supplier/product/StoreBrand.php new file mode 100644 index 0000000..2eab1f1 --- /dev/null +++ b/app/controller/supplier/product/StoreBrand.php @@ -0,0 +1,138 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product; + +use app\controller\supplier\AuthController; +use app\services\product\brand\StoreBrandServices; +use think\facade\App; + +/** + * 商品品牌控制器 + * Class StoreBrand + * @package app\controller\supplier\product + */ +class StoreBrand extends AuthController +{ + /** + * @var StoreBrandServices + */ + protected $service; + + /** + * StoreCategory constructor. + * @param App $app + * @param StoreBrandServices $service + */ + public function __construct(App $app, StoreBrandServices $service) + { + parent::__construct($app); + $this->service = $service; + } + + /** + * 品牌列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function index() + { + $where = $this->request->getMore([ + ['brand_name', ''], + ['pid', 0] + ]); + $where['is_del'] = 0; + $data = $this->service->getList($where); + return $this->success($data); + } + + /** + * 获取品牌cascader格式数据 + * @param $type + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function cascader_list($type = 1) + { + return $this->success($this->service->cascaderList($type)); + } + + /** + * 修改状态 + * @param string $is_show + * @param string $id + */ + public function set_show($is_show = '', $id = '') + { + if ($is_show == '' || $id == '') return $this->fail('缺少参数'); + $this->service->setShow($id, $is_show); + return $this->success($is_show == 1 ? '显示成功' : '隐藏成功'); + } + + /** + * 保存新增品牌 + * @return mixed + */ + public function save() + { + $data = $this->request->postMore([ + ['fid', []], + ['brand_name', ''], + ['sort', 0], + ['is_show', 0] + ]); + if (!$data['brand_name']) { + return $this->fail('请输入品牌名称'); + } + if (iconv_strlen($data['brand_name'], 'UTF-8') > 10) { + return $this->fail('品牌名称过长'); + } + $this->service->createData($data); + return $this->success('添加品牌成功!'); + } + + /** + * 更新品牌 + * @param $id + * @return mixed + */ + public function update($id) + { + $data = $this->request->postMore([ + ['fid', []], + ['brand_name', ''], + ['sort', 0], + ['is_show', 0] + ]); + if (!$data['brand_name']) { + return $this->fail('请输入品牌名称'); + } + if (iconv_strlen($data['brand_name'], 'UTF-8') > 10) { + return $this->fail('品牌名称过长'); + } + $this->service->editData($id, $data); + return $this->success('修改成功!'); + } + + /** + * 删除品牌 + * @param $id + * @return mixed + */ + public function delete($id) + { + $this->service->del((int)$id); + return $this->success('删除成功!'); + } +} diff --git a/app/controller/supplier/product/StoreProduct.php b/app/controller/supplier/product/StoreProduct.php new file mode 100644 index 0000000..0cc9dab --- /dev/null +++ b/app/controller/supplier/product/StoreProduct.php @@ -0,0 +1,545 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product; + + +use app\jobs\BatchHandleJob; +use app\services\other\queue\QueueServices; +use app\services\product\branch\StoreBranchProductAttrValueServices; +use app\services\product\branch\StoreBranchProductServices; +use app\services\product\category\StoreProductCategoryServices; +use app\services\product\product\StoreProductBatchProcessServices; +use app\services\product\product\StoreProductServices; +use app\services\product\sku\StoreProductAttrServices; +use app\services\product\sku\StoreProductAttrValueServices; +use app\services\user\label\UserLabelCateServices; +use app\services\user\label\UserLabelServices; +use crmeb\services\UploadService; +use think\facade\App; +use app\controller\supplier\AuthController; + +/** + * Class StoreProduct + * @package app\controller\supplier\product + */ +class StoreProduct extends AuthController +{ + protected $services; + protected $branchServices; + + /** + * @param App $app + * @param StoreProductServices $service + * @param StoreBranchProductServices $branchServices + */ + public function __construct(App $app, StoreProductServices $service, StoreBranchProductServices $branchServices) + { + parent::__construct($app); + $this->services = $service; + $this->branchServices = $branchServices; + } + + /** + * 显示资源列表头部 + * @return mixed + */ + public function type_header(StoreProductCategoryServices $storeProductCategoryServices) + { + $where = $this->request->getMore([ + ['store_name', ''], + ['cate_id', ''], + ['type', 1, '', 'status'], + ['show_type', ''], + ['sales', 'normal'], + ['pid', ''], + ['data', '', '', 'time'], + ['store_label_id', ''], + ['brand_id', ''] + ]); + $cateId = $where['cate_id']; + if ($cateId) { + $cateId = is_string($cateId) ? [$cateId] : $cateId; + $cateId = array_merge($cateId, $storeProductCategoryServices->getColumn(['pid' => $cateId], 'id')); + $cateId = array_unique(array_diff($cateId, [0])); + } + $where['cate_id'] = $cateId; + $where['supplier_id'] = $this->supplierId; + $list = $this->services->getHeader(0, $where); + return app('json')->success(compact('list')); + } + + /** + * 显示资源列表 + * @return mixed + */ + public function index(StoreProductCategoryServices $storeProductCategoryServices) + { + $where = $this->request->getMore([ + ['store_name', ''], + ['cate_id', ''], + ['type', 1, '', 'status'], + ['show_type', ''], + ['sales', 'normal'], + ['pid', ''], + ['data', '', '', 'time'], + ['store_label_id', ''], + ['brand_id', ''] + ]); + $cateId = $where['cate_id']; + if ($cateId) { + $cateId = is_string($cateId) ? [$cateId] : $cateId; + $cateId = array_merge($cateId, $storeProductCategoryServices->getColumn(['pid' => $cateId], 'id')); + $cateId = array_unique(array_diff($cateId, [0])); + } + $where['cate_id'] = $cateId; + $where['relation_id'] = $this->supplierId; + $where['type'] = 2; + $data = $this->services->getList($where); + return app('json')->success($data); + } + + /** + * 获取选择的商品列表 + * @return mixed + */ + public function search_list() + { + $where = $this->request->getMore([ + ['cate_id', ''], + ['store_name', ''], + ['type', 1, '', 'status'], + ['is_live', 0], + ['is_new', ''], + ['is_vip_product', ''], + ['is_presale_product', ''], + ['data', '', '', 'time'], + ['store_label_id', ''], + ['brand_id', ''] + ]); + $where['is_show'] = 1; + $where['is_del'] = 0; + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + /** @var StoreProductCategoryServices $storeCategoryServices */ + $storeCategoryServices = app()->make(StoreProductCategoryServices::class); + if ($where['cate_id'] !== '') { + if ($storeCategoryServices->value(['id' => $where['cate_id']], 'pid')) { + $where['sid'] = $where['cate_id']; + } else { + $where['cid'] = $where['cate_id']; + } + } + unset($where['cate_id']); + $list = $this->services->searchList($where); + return $this->success($list); + } + + /** + * 获取分类cascader格式数据 + * @param $type + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function cascader_list(StoreProductCategoryServices $services) + { + return app('json')->success($services->cascaderList(2, (int)$this->supplierId)); + } + + /** + * 获取商品详细信息 + * @param int $id + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function read($id = 0) + { + return app('json')->success($this->services->getInfo((int)$id)); + } + + /** + * 保存新建或编辑 + * @param StoreProductAttrServices $attrServices + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function save(StoreProductAttrServices $attrServices, $id) + { + $data = $this->request->postMore([ + ['product_type', 0],//商品类型 + ['supplier_id', 0],//供应商ID + ['cate_id', []], + ['store_name', ''], + ['store_info', ''], + ['keyword', ''], + ['unit_name', '件'], + ['recommend_image', ''], + ['slider_image', []], + ['is_sub', []],//佣金是单独还是默认 + ['sort', 0], +// ['sales', 0], + ['ficti', 100], + ['give_integral', 0], + ['is_show', 0], + ['is_hot', 0], + ['is_benefit', 0], + ['is_best', 0], + ['is_new', 0], + ['mer_use', 0], + ['is_postage', 0], + ['is_good', 0], + ['description', ''], + ['spec_type', 0], + ['video_open', 0], + ['video_link', ''], + ['items', []], + ['attrs', []], + ['recommend', []],//商品推荐 + ['activity', []], + ['coupon_ids', []], + ['label_id', []], + ['command_word', ''], + ['tao_words', ''], + ['type', 0, '', 'is_copy'], + ['delivery_type', []],//物流设置 + ['freight', 1],//运费设置 + ['postage', 0],//邮费 + ['temp_id', 0],//运费模版 + ['recommend_list', []], + ['brand_id', []], + ['soure_link', ''], + ['bar_code', ''], + ['code', ''], + ['is_support_refund', 1],//是否支持退款 + ['is_presale_product', 0],//预售商品开关 + ['presale_time', []],//预售时间 + ['presale_day', 0],//预售发货日 + ['is_vip_product', 0],//是否付费会员商品 + ['auto_on_time', 0],//自动上架时间 + ['auto_off_time', 0],//自动下架时间 + ['custom_form', []],//自定义表单 + ['system_form_id', 0],//系统表单ID + ['store_label_id', []],//商品标签 + ['ensure_id', []],//商品保障服务区 + ['specs', []],//商品参数 + ['specs_id', 0],//商品参数ID + ['is_limit', 0],//是否限购 + ['limit_type', 0],//限购类型 + ['limit_num', 0]//限购数量 + ]); + $data['is_verify'] = 0; + //供应商商品不支持门店 + $data['delivery_type'] = [1]; + $this->services->save((int)$id, $data, 2, (int)$this->supplierId); + + $this->services->cacheTag()->clear(); + $attrServices->cacheTag()->clear(); + return $this->success($id ? '保存商品信息成功' : '添加商品成功!'); + } + + /** + * 保存编辑 + * @param int $id + * @param StoreBranchProductServices $services + * @return mixed + */ + public function update($id = 0, StoreBranchProductAttrValueServices $services) + { + $data = $this->request->postMore([ + ['attrs', []], + ['label_id', []], + ['is_show', 1] + ]); + $storeId = $this->storeId; + $services->updataAll((int)$id, (array)$data, (int)$storeId); + return app('json')->success('保存商品信息成功'); + } + + + /** + * 获取关联用户标签列表 + * @param UserLabelServices $service + * @return mixed + */ + public function getUserLabel(UserLabelCateServices $userLabelCateServices, UserLabelServices $service) + { + $cate = $userLabelCateServices->getLabelCateAll(2, (int)$this->supplierId); + $data = []; + $label = []; + if ($cate) { + foreach ($cate as $value) { + $data[] = [ + 'id' => $value['id'] ?? 0, + 'value' => $value['id'] ?? 0, + 'label_cate' => 0, + 'label_name' => $value['name'] ?? '', + 'label' => $value['name'] ?? '', + 'store_id' => $value['store_id'] ?? 0, + 'type' => $value['type'] ?? 1, + ]; + } + $label = $service->getColumn(['type' => 2, 'relation_id' => $this->supplierId], '*'); + if ($label) { + foreach ($label as &$item) { + $item['label'] = $item['label_name']; + $item['value'] = $item['id']; + } + } + } + return app('json')->success($service->get_tree_children($data, $label)); + } + + /** + * 修改状态 + * @param string $is_show + * @param string $id + * @return mixed + */ + public function set_show($is_show = '', $id = '', StoreBranchProductServices $services) + { + if (!$id) return $this->fail('缺少商品ID'); + $services->setShow($this->supplierId, $id, $is_show); + return $this->success($is_show == 1 ? '上架成功' : '下架成功'); + } + + /** + * 获取规格模板 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function get_rule() + { + return $this->success($this->services->getRule(2, (int)$this->supplierId)); + } + + /** + * 获取商品详细信息 + * @param int $id + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function get_product_info($id = 0) + { + return $this->success($this->services->getInfo((int)$id)); + } + + + /** + * 获取运费模板列表 + * @return mixed + */ + public function get_template() + { + return $this->success($this->services->getTemp(2, (int)$this->supplierId)); + } + + /** + * 获取视频上传token + * @return mixed + * @throws \Exception + */ + public function getTempKeys() + { + $upload = UploadService::init(); + $type = (int)sys_config('upload_type', 1); + $key = $this->request->get('key', ''); + $path = $this->request->get('path', ''); + $contentType = $this->request->get('contentType', ''); + if ($type === 5) { + if (!$key || !$contentType) { + return app('json')->fail('缺少参数'); + } + $re = $upload->getTempKeys($key, $path, $contentType); + } else { + $re = $upload->getTempKeys(); + } + return $re ? $this->success($re) : $this->fail($upload->getError()); + } + + /** + * 获取商品所有规格数据 + * @param StoreBranchProductAttrValueServices $services + * @param $id + * @return mixed + */ + public function getAttrs(StoreBranchProductAttrValueServices $services, $id) + { + if (!$id) { + return $this->fail('缺少商品ID'); + } + return $this->success($services->getStoreProductAttr((int)$id)); + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + //删除商品检测是否有参与活动 + $this->services->checkActivity($id); + $res = $this->services->del($id); + event('product.delete', [$id]); + return $this->success($res); + } + + /** + * 生成规格列表 + * @param int $id + * @param int $type + * @return mixed + */ + public function is_format_attr($id = 0, $type = 0) + { + $data = $this->request->postMore([ + ['attrs', []], + ['items', []], + ['product_type', 0] + ]); + if ($id > 0 && $type == 1) $this->services->checkActivity($id); + $info = $this->services->getAttr($data, $id, $type, 2); + return $this->success(compact('info')); + } + + /** + * 快速修改商品规格库存 + * @param StoreProductAttrValueServices $services + * @param $id + * @return mixed + */ + public function saveProductAttrsStock(StoreProductAttrValueServices $services, $id) + { + if (!$id) { + return $this->fail('缺少商品ID'); + } + [$attrs] = $this->request->getMore([ + ['attrs', []] + ], true); + if (!$attrs) { + return $this->fail('请重新修改规格库存'); + } + foreach ($attrs as $attr) { + if (!isset($attr['unique']) || !isset($attr['pm']) || !isset($attr['stock'])) { + return $this->fail('请重新修改规格库存'); + } + } + return $this->success(['stock' => $services->saveProductAttrsStock((int)$id, $attrs)]); + } + + /** + * 设置批量商品上架 + * @return mixed + */ + public function product_show() + { + [$ids, $all, $where] = $this->request->postMore([ + ['ids', []], + ['all', 0], + ['where', []], + ], true); + if ($all == 0) {//单页不走队列 + if (empty($ids)) return $this->fail('请选择需要上架的商品'); + $this->services->setShow($ids, 1); + return $this->success('上架成功'); + } + if ($all == 1) { + $ids = []; + if (isset($where['type'])) { + $where['status'] = $where['type']; + unset($where['type']); + } + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + } + $type = 4;//商品上架 + /** @var QueueServices $queueService */ + $queueService = app()->make(QueueServices::class); + $queueService->setQueueData($where, 'id', $ids, $type); + //加入队列 + BatchHandleJob::dispatch(['up', $type]); + return $this->success('后台程序已执商品上架任务!'); + } + + /** + * 设置批量商品下架 + * @return mixed + */ + public function product_unshow() + { + [$ids, $all, $where] = $this->request->postMore([ + ['ids', []], + ['all', 0], + ['where', []], + ], true); + if ($all == 0) {//单页不走队列 + if (empty($ids)) return $this->fail('请选择需要下架的商品'); + $this->services->setShow($ids, 0); + return $this->success('下架成功'); + } + if ($all == 1) { + $all_ids = $this->services->getColumn(['is_show' => 1, 'is_del' => 0, 'type' => 2, 'relation_id' => $this->supplierId], 'id'); + $this->services->checkActivity($all_ids); + $ids = []; + if (isset($where['type'])) { + $where['status'] = $where['type']; + unset($where['type']); + } + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + } + $type = 4;//商品下架 + /** @var QueueServices $queueService */ + $queueService = app()->make(QueueServices::class); + $queueService->setQueueData($where, 'id', $ids, $type); + //加入队列 + BatchHandleJob::dispatch(['down', $type]); + return $this->success('后台程序已执商品下架任务!'); + } + + /** + * 商品批量操作 + * @param StoreProductBatchProcessServices $batchProcessServices + * @return mixed + */ + public function batchProcess(StoreProductBatchProcessServices $batchProcessServices) + { + [$type, $ids, $all, $where, $data] = $this->request->postMore([ + ['type', 1], + ['ids', ''], + ['all', 0], + ['where', ""], + ['data', []] + ], true); + if (!$ids && $all == 0) return $this->fail('请选择批处理商品'); + if (!$data) { + return $this->fail('请选择批处理数据'); + } + if (isset($where['type'])) { + $where['status'] = $where['type']; + unset($where['type']); + } + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + //批量操作 + $batchProcessServices->batchProcess((int)$type, $ids, $data, !!$all, $where); + return app('json')->success('已加入消息队列,请稍后查看'); + } +} diff --git a/app/controller/supplier/product/StoreProductCategory.php b/app/controller/supplier/product/StoreProductCategory.php new file mode 100644 index 0000000..1b68d50 --- /dev/null +++ b/app/controller/supplier/product/StoreProductCategory.php @@ -0,0 +1,171 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product; + +use app\controller\supplier\AuthController; +use app\services\product\category\StoreProductCategoryServices; +use think\facade\App; + +/** + * 商品分类控制器 + * Class StoreProductCategory + */ +class StoreProductCategory extends AuthController +{ + /** + * @var StoreProductCategoryServices + */ + protected $service; + + /** + * StoreCategory constructor. + * @param App $app + * @param StoreProductCategoryServices $service + */ + public function __construct(App $app, StoreProductCategoryServices $service) + { + parent::__construct($app); + $this->service = $service; + } + + /** + * 分类列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function index() + { + $where = $this->request->getMore([ + ['is_show', ''], + ['pid', 0], + ['cate_name', ''], + ]); +// $where['type'] = 2; +// $where['relation_id'] = $this->supplierId; + $where['pid'] = (int)$where['pid']; + $data = $this->service->getList($where); + return $this->success($data); + } + + /** + * 商品分类搜索 + * @return mixed + */ + public function tree_list($type) + { + $list = $this->service->getTierList(1, $type); + return $this->success($list); + } + + /** + * 获取分类cascader格式数据 + * @param $type + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function cascader_list($type = 1) + { + return $this->success($this->service->cascaderList(0, 0, !$type)); + } + + /** + * 修改状态 + * @param string $is_show + * @param string $id + */ + public function set_show($is_show = '', $id = '') + { + if ($is_show == '' || $id == '') return $this->fail('缺少参数'); + $this->service->setShow($id, $is_show); + return $this->success($is_show == 1 ? '显示成功' : '隐藏成功'); + } + + /** + * 生成新增表单 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function create() + { + return $this->success($this->service->createForm(1)); + } + + /** + * 保存新增分类 + * @return mixed + */ + public function save() + { + $data = $this->request->postMore([ + ['pid', 0], + ['cate_name', ''], + ['pic', ''], + ['big_pic', ''], + ['sort', 0], + ['is_show', 0] + ]); + if (!$data['cate_name']) { + return $this->fail('请输入分类名称'); + } + $data['type'] = 2; + $data['relation_id'] = $this->supplierId; + $this->service->createData($data); + return $this->success('添加分类成功!'); + } + + /** + * 生成更新表单 + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id) + { + return $this->success($this->service->editForm((int)$id, 1)); + } + + /** + * 更新分类 + * @param $id + * @return mixed + */ + public function update($id) + { + $data = $this->request->postMore([ + ['pid', 0], + ['cate_name', ''], + ['pic', ''], + ['big_pic', ''], + ['sort', 0], + ['is_show', 0] + ]); + if (!$data['cate_name']) { + return $this->fail('请输入分类名称'); + } + $this->service->editData($id, $data); + return $this->success('修改成功!'); + } + + /** + * 删除分类 + * @param $id + * @return mixed + */ + public function delete($id) + { + $this->service->del((int)$id); + return $this->success('删除成功!'); + } +} diff --git a/app/controller/supplier/product/StoreProductReply.php b/app/controller/supplier/product/StoreProductReply.php new file mode 100644 index 0000000..1b945ae --- /dev/null +++ b/app/controller/supplier/product/StoreProductReply.php @@ -0,0 +1,75 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product; + +use app\controller\supplier\AuthController; +use app\services\product\product\StoreProductReplyServices; +use think\facade\App; + +/** + * 评论管理 控制器 + * Class StoreProductReply + * @package app\controller\supplier\product + */ +class StoreProductReply extends AuthController +{ + public function __construct(App $app, StoreProductReplyServices $service) + { + parent::__construct($app); + $this->services = $service; + } + + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index() + { + $where = $this->request->getMore([ + ['is_reply', ''], + ['store_name', ''], + ['account', ''], + ['data', ''], + ['product_id', 0] + ]); + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + $list = $this->services->sysPage($where); + return $this->success($list); + } + + /** + * 删除评论 + * @param $id + * @return mixed + */ + public function delete($id) + { + $this->services->del($id); + return $this->success('删除成功!'); + } + + /** + * 回复评论 + * @param $id + * @return mixed + */ + public function set_reply($id) + { + [$content] = $this->request->postMore([ + ['content', ''] + ], true); + $this->services->setReply((int)$id, $content, 2, (int)$this->supplierId); + return $this->success('回复成功!'); + } + +} diff --git a/app/controller/supplier/product/StoreProductRule.php b/app/controller/supplier/product/StoreProductRule.php new file mode 100644 index 0000000..e7448d4 --- /dev/null +++ b/app/controller/supplier/product/StoreProductRule.php @@ -0,0 +1,99 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product; + +use app\controller\supplier\AuthController; +use app\jobs\BatchHandleJob; +use app\services\other\queue\QueueServices; +use app\services\product\sku\StoreProductRuleServices; +use think\facade\App; + +/** + * 规则管理 + * Class StoreProductRule + * @package app\controller\supplier\product + */ +class StoreProductRule extends AuthController +{ + + public function __construct(App $app, StoreProductRuleServices $service) + { + parent::__construct($app); + $this->services = $service; + } + + /** + * 规格列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function index() + { + $where = $this->request->getMore([ + ['rule_name', ''] + ]); + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + $list = $this->services->getList($where); + return $this->success($list); + } + + /** + * 保存规格 + * @param $id + * @return mixed + */ + public function save($id) + { + $data = $this->request->postMore([ + ['rule_name', ''], + ['spec', []] + ]); + if (!$data['rule_name']) { + return $this->fail('请输入分类名称'); + } + $data['type'] = 2; + $data['relation_id'] = $this->supplierId; + $this->services->save($id, $data, 2, (int)$this->supplierId); + return $this->success('保存成功!'); + } + + /** + * 获取规格信息 + * @param $id + * @return mixed + */ + public function read($id) + { + $info = $this->services->getInfo($id); + return $this->success($info); + } + + /** + * 删除指定资源 + * @param $id + * @return mixed + */ + public function delete($id) + { + if (!$id) { + return $this->fail('缺少ID'); + } + $info = $this->services->getInfo((int)$id); + if (!$info) { + return $this->fail('删除的数据不存在'); + } + $this->services->delete($id); + return $this->success('删除成功!'); + } +} diff --git a/app/controller/supplier/product/StoreProductUnit.php b/app/controller/supplier/product/StoreProductUnit.php new file mode 100644 index 0000000..7e25b45 --- /dev/null +++ b/app/controller/supplier/product/StoreProductUnit.php @@ -0,0 +1,173 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product; + +use app\controller\supplier\AuthController; +use app\services\product\product\StoreProductUnitServices; +use think\facade\App; +use app\Request; + +/** + * 商品单位 + * Class StoreProductUnit + * @package app\controller\supplier\product + */ +class StoreProductUnit extends AuthController +{ + /** + * StoreProductUnit constructor. + * @param App $app + * @param StoreProductUnitServices $services + */ + public function __construct(App $app, StoreProductUnitServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 获取所有商品单位 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getAllUnit() + { + return $this->success($this->services->getAllUnitList(2, (int)$this->supplierId)); + } + + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index(Request $request) + { + $where = $request->postMore([ + ['name', ''] + ]); + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + $where['status'] = 1; + $where['is_del'] = 0; + return $this->success($this->services->getUnitList($where)); + } + + /** + * 显示创建资源表单页. + * + * @return \think\Response + */ + public function create() + { + return $this->success($this->services->createForm()); + } + + /** + * 保存新建的资源 + * + * @param \app\Request $request + * @return \think\Response + */ + public function save(Request $request) + { + $data = $request->postMore([ + ['name', ''], + ['sort', 0] + ]); + + validate(\app\validate\admin\product\StoreProductUnitValidate::class)->scene('get')->check(['name' => $data['name']]); + + if ($this->services->getCount(['name' => $data['name'], 'is_del' => 0, 'type' => 2, 'relation_id' => $this->supplierId])) { + return $this->fail('单位已经存在,请勿重复添加'); + } + $data['add_time'] = time(); + if ($this->services->save($data)) { + return $this->success('保存成功'); + } else { + return $this->fail('保存失败'); + } + } + + /** + * 显示指定的资源 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + if (!$id) { + return $this->fail('缺少ID'); + } + $info = $this->services->get($id); + if (!$info) { + return $this->fail('获取商品单位失败'); + } + return $this->success($info->toArray()); + } + + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit($id) + { + return $this->success($this->services->updateForm((int)$id)); + } + + /** + * 保存更新的资源 + * + * @param \app\Request $request + * @param int $id + * @return \think\Response + */ + public function update(Request $request, $id) + { + $data = $request->postMore([ + ['name', ''], + ['sort', 0] + ]); + + validate(\app\validate\admin\product\StoreProductUnitValidate::class)->scene('get')->check(['name' => $data['name']]); + + $unit = $this->services->getOne(['name' => $data['name'], 'is_del' => 0, 'type' => 2, 'relation_id' => $this->supplierId]); + if ($unit && $unit['id'] != $id) { + return $this->fail('单位名称已经存在'); + } + if ($this->services->update($id, $data)) { + return $this->success('修改成功'); + } else { + return $this->fail('修改失败'); + } + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + if (!$id || !($info = $this->services->get($id))) { + return $this->fail('删除的数据不存在'); + } + if ($info && $info['is_del'] == 0) { + $this->services->update($id, ['is_del' => 1]); + } + return $this->success('删除成功'); + } +} diff --git a/app/controller/supplier/product/ensure/StoreProductEnsure.php b/app/controller/supplier/product/ensure/StoreProductEnsure.php new file mode 100644 index 0000000..66d202c --- /dev/null +++ b/app/controller/supplier/product/ensure/StoreProductEnsure.php @@ -0,0 +1,171 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product\ensure; + +use app\controller\supplier\AuthController; +use app\Request; +use app\services\product\ensure\StoreProductEnsureServices; +use think\facade\App; + +/** + * 商品保障服务 + * Class StoreProductEnsure + * @package app\controller\supplier\product\ensure + */ +class StoreProductEnsure extends AuthController +{ + /** + * @var StoreProductEnsureServices + */ + protected $services; + + /** + * StoreProductEnsure constructor. + * @param App $app + * @param StoreProductEnsureServices $services + */ + public function __construct(App $app, StoreProductEnsureServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 获取保障服务列表 + * @param Request $request + * @return mixed + */ + public function index(Request $request) + { + $where = $request->postMore([ + ['name', ''] + ]); + $where['relation_id'] = $this->supplierId; + $where['type'] = 2; + return $this->success($this->services->getEnsureList($where)); + } + + /** + * 获取保障服务列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function allEnsure() + { + return $this->success($this->services->getAllEnsure(2, (int)$this->supplierId)); + } + + + /** + * 生成新增表单 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function create() + { + return $this->success($this->services->createForm()); + } + + /** + * 保存新增保障服务 + * @return mixed + */ + public function save() + { + $data = $this->request->postMore([ + ['name', ''], + ['image', ''], + ['desc', ''], + ['sort', 0], + ]); + if (!$data['name']) { + return $this->fail('请输入保障服务条款'); + } + if (!$data['image']) return $this->fail('请上传图标'); + if ($this->services->getOne(['name' => $data['name']])) { + return $this->fail('保障服务条款已存在'); + } + $data['type'] = 2; + $data['relation_id'] = $this->supplierId; + $data['add_time'] = time(); + $this->services->save($data); + return $this->success('添加保障服务成功!'); + } + + /** + * 生成更新表单 + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id) + { + return $this->success($this->services->editForm((int)$id)); + } + + /** + * 更新保障服务 + * @param $id + * @return mixed + */ + public function update($id) + { + $data = $this->request->postMore([ + ['name', ''], + ['image', ''], + ['desc', ''], + ['sort', 0], + ]); + if (!$data['name']) { + return $this->fail('请输入保障服务条款'); + } + if (!$data['image']) return $this->fail('请上传图标'); + $cate = $this->services->getOne(['name' => $data['name']]); + if ($cate && $cate['id'] != $id) { + return $this->fail('保障服务条款已存在'); + } + $this->services->update($id, $data); + return $this->success('修改成功!'); + } + + /** + * 设置保障服务是否显示 + * @param $id + * @param $is_show + * @return mixed + */ + public function set_show($id, $is_show) + { + ($is_show == '' || $id == '') && $this->fail('缺少参数'); + $res = $this->services->update((int)$id, ['status' => (int)$is_show]); + if ($res) { + return $this->success('设置成功'); + } else { + return $this->fail('设置失败'); + } + } + + /** + * 删除保障服务 + * @param $id + * @return mixed + */ + public function delete($id) + { + if (!$id || !$this->services->count(['id' => $id])) { + return $this->fail('删除的数据不存在'); + } + $this->services->delete((int)$id); + return $this->success('删除成功!'); + } +} diff --git a/app/controller/supplier/product/label/StoreProductLabel.php b/app/controller/supplier/product/label/StoreProductLabel.php new file mode 100644 index 0000000..59bdd28 --- /dev/null +++ b/app/controller/supplier/product/label/StoreProductLabel.php @@ -0,0 +1,128 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product\label; + +use app\controller\supplier\AuthController; +use app\services\product\label\StoreProductLabelCateServices; +use app\services\product\label\StoreProductLabelServices; +use think\facade\App; +use app\Request; + +/** + * 商品标签 + * Class StoreProductLabel + * @package app\controller\supplier\product\label + */ +class StoreProductLabel extends AuthController +{ + /** + * StoreProductLabel constructor. + * @param App $app + * @param StoreProductLabelServices $services + */ + public function __construct(App $app, StoreProductLabelServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + + /** + * 带标签的标签组树形结构 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function tree_list() + { + return $this->success($this->services->getProductLabelTreeList()); + } + + /** + * 获取商品标签列表 + * @return mixed + */ + public function allLabel() + { + return $this->success($this->services->getList(2, (int)$this->supplierId)); + } + + /** + * 添加、编辑商品标签 + * @param Request $request + * @param $id + * @return mixed + */ + public function save(Request $request, $id) + { + $data = $request->postMore([ + ['label_cate', 0], + ['label_name', ''], + ]); + if (!$data['label_cate']) { + return $this->fail('请选择标签组'); + } + if (!trim($data['label_name'])) { + return $this->fail('请输入标签名称'); + } + $label = $this->services->getOne(['label_cate' => $data['label_cate'], 'label_name' => $data['label_name'], 'type' => 2, 'relation_id' => $this->supplierId]); + if ($id) { + if ($label && $id != $label['id']) { + return $this->fail('标签已经存在'); + } + if ($this->services->update($id, $data)) { + return $this->success('编辑成功'); + } else { + return $this->fail('编辑失败'); + } + } else { + if ($label) { + return $this->fail('标签已经存在'); + } + $data['type'] = 2; + $data['relation_id'] = $this->supplierId; + $data['add_time'] = time(); + if ($this->services->save($data)) { + return $this->success('保存成功'); + } else { + return $this->fail('保存失败'); + } + } + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + if (!$id || !$this->services->count(['id' => $id])) { + return $this->fail('删除的数据不存在'); + } + $this->services->delete($id); + return $this->success('删除成功'); + } + + /** + * 获取表单 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getLabelForm() + { + return $this->success($this->services->getLabelForm()); + } +} diff --git a/app/controller/supplier/product/label/StoreProductLabelCate.php b/app/controller/supplier/product/label/StoreProductLabelCate.php new file mode 100644 index 0000000..9d71d87 --- /dev/null +++ b/app/controller/supplier/product/label/StoreProductLabelCate.php @@ -0,0 +1,144 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product\label; + +use app\controller\supplier\AuthController; +use app\Request; +use app\services\product\label\StoreProductLabelCateServices; +use app\services\product\label\StoreProductLabelServices; +use think\facade\App; + +/** + * 商品标签组 + * Class StoreProductLabelCate + * @package app\controller\supplier\product\label + */ +class StoreProductLabelCate extends AuthController +{ + /** + * @var StoreProductLabelCateServices + */ + protected $services; + + /** + * StoreProductLabelCate constructor. + * @param App $app + * @param StoreProductLabelCateServices $services + */ + public function __construct(App $app, StoreProductLabelCateServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 获取标签组列表 + * @param Request $request + * @return mixed + */ + public function index(Request $request) + { + $where = $request->postMore([ + ['name', ''] + ]); + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + $where['group'] = 2; + $where['product_label'] = 1; + return $this->success($this->services->getProductLabelCateList($where)); + } + + + /** + * 生成新增表单 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function create() + { + return $this->success($this->services->createForm()); + } + + /** + * 保存新增标签组 + * @return mixed + */ + public function save() + { + $data = $this->request->postMore([ + ['name', ''], + ['sort', 0], + ]); + if (!trim($data['name'])) { + return $this->fail('请输入标签组名称'); + } + if ($this->services->getOne(['name' => $data['name'], 'group' => 2, 'type' => 2, 'relation_id' => $this->supplierId])) { + return $this->fail('标签组已存在'); + } + $data['type'] = 2; + $data['relation_id'] = $this->supplierId; + $data['group'] = 2; + $data['add_time'] = time(); + $this->services->save($data); + return $this->success('添加标签组成功!'); + } + + /** + * 生成更新表单 + * @param $id + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function edit($id) + { + return $this->success($this->services->editForm((int)$id)); + } + + /** + * 更新标签组 + * @param $id + * @return mixed + */ + public function update($id) + { + $data = $this->request->postMore([ + ['name', ''], + ['sort', 0], + ]); + if (!$data['name']) { + return $this->fail('请输入标签组名称'); + } + $cate = $this->services->getOne(['name' => $data['name'], 'group' => 2, 'type' => 2, 'relation_id' => $this->supplierId]); + if ($cate && $cate['id'] != $id) { + return $this->fail('标签组已存在'); + } + $this->services->update($id, $data); + return $this->success('修改成功!'); + } + + /** + * 删除标签组 + * @param StoreProductLabelServices $labelServices + * @param $id + * @return mixed + */ + public function delete(StoreProductLabelServices $labelServices, $id) + { + if (!$id || !$this->services->count(['id' => $id])) { + return $this->fail('删除的数据不存在'); + } + if ($labelServices->count(['label_cate' => $id])) { + return $this->fail('标签组下有标签不能删除'); + } + $this->services->delete((int)$id); + return $this->success('删除成功!'); + } +} diff --git a/app/controller/supplier/product/shipping/ShippingTemplates.php b/app/controller/supplier/product/shipping/ShippingTemplates.php new file mode 100644 index 0000000..14f3850 --- /dev/null +++ b/app/controller/supplier/product/shipping/ShippingTemplates.php @@ -0,0 +1,119 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product\shipping; + +use app\controller\supplier\AuthController; +use app\services\product\shipping\ShippingTemplatesServices; +use app\services\other\SystemCityServices; +use think\facade\App; + +/** + * 运费模板 + * Class ShippingTemplates + * @package app\controller\supplier\setting + */ +class ShippingTemplates extends AuthController +{ + /** + * 构造方法 + * ShippingTemplates constructor. + * @param App $app + * @param ShippingTemplatesServices $services + */ + public function __construct(App $app, ShippingTemplatesServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 运费模板列表 + * @return mixed + */ + public function temp_list() + { + $where = $this->request->getMore([ + [['name', 's'], ''] + ]); + $where['type'] = 2; + $where['relation_id'] = $this->supplierId; + return $this->success($this->services->getShippingList($where)); + } + + /** + * 修改 + * @return string + * @throws \Exception + */ + public function edit($id) + { + return $this->success($this->services->getShipping((int)$id)); + } + + /** + * 保存或者修改 + * @param int $id + */ + public function save($id = 0) + { + $data = $this->request->postMore([ + [['region_info', 'a'], []], + [['appoint_info', 'a'], []], + [['no_delivery_info', 'a'], []], + [['sort', 'd'], 0], + [['type', 'd'], 0, '', 'group'], + [['name', 's'], ''], + [['appoint', 'd'], 0], + [['no_delivery', 'd'], 0] + ]); + $this->validate($data, \app\validate\admin\setting\ShippingTemplatesValidate::class, 'save'); + $temp['type'] = 2; + $temp['relation_id'] = $this->supplierId; + $temp['name'] = $data['name']; + $temp['group'] = $data['group']; + $temp['appoint'] = $data['appoint'] && $data['appoint_info'] ? 1 : 0; + $temp['no_delivery'] = $data['no_delivery'] && $data['no_delivery_info'] ? 1 : 0; + $temp['sort'] = $data['sort']; + $temp['add_time'] = time(); + $this->services->save((int)$id, $temp, $data); + event('product.shipping.update'); + return $this->success((int)$id ? '修改成功!' : '添加成功!'); + } + + /** + * 删除运费模板 + */ + public function delete() + { + [$id] = $this->request->getMore([ + [['id', 'd'], 0], + ], true); + if ($id == 1) { + return $this->fail('默认模板不能删除'); + } else { + $this->services->detete($id); + event('product.shipping.update'); + return $this->success('删除成功'); + } + } + + /** + * 城市数据 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function city_list(SystemCityServices $services) + { + return $this->success($services->getShippingCity()); + } +} diff --git a/app/controller/supplier/product/specs/StoreProductSpecs.php b/app/controller/supplier/product/specs/StoreProductSpecs.php new file mode 100644 index 0000000..cd2a8b7 --- /dev/null +++ b/app/controller/supplier/product/specs/StoreProductSpecs.php @@ -0,0 +1,154 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\product\specs; + +use app\controller\supplier\AuthController; +use app\services\product\specs\StoreProductSpecsServices; +use app\services\product\specs\StoreProductSpecsTemplateServices; +use think\facade\App; +use app\Request; + +/** + * 商品参数 + * Class StoreProductSpecs + * @package app\controller\supplier\product\specs + */ +class StoreProductSpecs extends AuthController +{ + /** + * 参数模版services + * @var StoreProductSpecsTemplateServices + */ + protected $templateServices; + + /** + * StoreProductSpecs constructor. + * @param App $app + * @param StoreProductSpecsServices $services + * @param StoreProductSpecsTemplateServices $templateServices + */ + public function __construct(App $app, StoreProductSpecsServices $services, StoreProductSpecsTemplateServices $templateServices) + { + parent::__construct($app); + $this->services = $services; + $this->templateServices = $templateServices; + } + + + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function index(Request $request) + { + $where = $request->postMore([ + ['name', ''] + ]); + return $this->success($this->templateServices->getProductSpecsTemplateList($where, 2, (int)$this->supplierId)); + } + + /** + * 显示资源列表 + * + * @return \think\Response + */ + public function allSpecs(Request $request) + { + return $this->success($this->templateServices->getAllSpecs(2, (int)$this->supplierId)); + } + + /** + * 获取参数模版信息 + * @param $id + * @return mixed + */ + public function getInfo($id) + { + if (!$id) return $this->fail('缺少参数ID'); + $temp = $this->templateServices->get(['id' => $id, 'group' => 3], ['*'], ['specs']); + if (!$temp) { + return $this->fail('参数模版不存在'); + } + return $this->success($temp->toArray()); + } + + + /** + * 添加、编辑商品参数模版 + * @param Request $request + * @param $id + * @return mixed + */ + public function save(Request $request, $id) + { + $data = $request->postMore([ + ['name', ''], + ['specs', []], + ['sort', ''], + ]); + if (!$data['name']) { + return $this->fail('请输入参数模版名称'); + } + $specs = $data['specs']; + unset($data['specs']); + $type = 2; + $supplier_id = (int)$this->supplierId; + $temp = $this->templateServices->getOne(['name' => $data['name'], 'group' => 3, 'type' => $type, 'relation_id' => $supplier_id]); + if ($id) { + if ($temp && $id != $temp['id']) { + return $this->fail('参数模版已经存在'); + } + $this->templateServices->transaction(function () use ($id, $data, $specs, $type, $supplier_id) { + if (!$this->templateServices->update($id, $data)) { + return $this->success('编辑失败'); + } + if (!$this->services->updateData($id, $specs)) { + return $this->success('编辑失败'); + } + }); + return $this->success('编辑成功'); + } else { + if ($temp) { + return $this->fail('参数模版已经存在'); + } + $data['type'] = $type; + $data['relation_id'] = $supplier_id; + $data['group'] = 3; + $data['add_time'] = time(); + $this->templateServices->transaction(function () use ($id, $data, $specs, $type, $supplier_id) { + if (!$res = $this->templateServices->save($data)) { + return $this->success('保存失败'); + } + if (!$this->services->saveData((int)$res->id, $specs, $type, $supplier_id)) { + return $this->success('保存失败'); + } + }); + return $this->success('保存成功'); + } + } + + /** + * 删除指定资源 + * + * @param int $id + * @return \think\Response + */ + public function delete($id) + { + if (!$id || !($this->templateServices->count(['id' => $id]))) { + return $this->fail('删除的数据不存在'); + } + $this->templateServices->delete($id); + $this->services->delete(['temp_id' => $id]); + return $this->success('删除成功'); + } +} diff --git a/app/controller/supplier/queue/Queue.php b/app/controller/supplier/queue/Queue.php new file mode 100644 index 0000000..50592de --- /dev/null +++ b/app/controller/supplier/queue/Queue.php @@ -0,0 +1,118 @@ + +// +---------------------------------------------------------------------- + +namespace app\controller\supplier\queue; + +use app\controller\supplier\AuthController; +use app\services\other\queue\QueueAuxiliaryServices; +use app\services\other\queue\QueueServices; +use think\facade\App; + +/** + * Class Queue + * @package app\controller\supplier + */ +class Queue extends AuthController +{ + /** + * Queue constructor. + * @param App $app + * @param QueueServices $queueServices + */ + public function __construct(App $app, QueueServices $queueServices) + { + parent::__construct($app); + $this->services = $queueServices; + } + + /** + * 队列任务列表 + * @return mixed + */ + public function index() + { + $where = $this->request->getMore([ + ['data', '', '', 'time'], + ['type', []], + ['status', [0, 1, 2, 3]], + ['page', 1], + ['limit', 20], + ]); + $data = $this->services->getList($where); + return $this->success($data); + } + + /** + * 批量发货记录 + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function delivery_log($id, $type) + { + /** @var QueueAuxiliaryServices $auxiliaryService */ + $auxiliaryService = app()->make(QueueAuxiliaryServices::class); + $data = $auxiliaryService->deliveryLogList(['binding_id' => $id, 'type' => $type]); + return $this->success($data); + } + + /** + * 再次执行批量任务 + * @param $id + * @param $type + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function again_do_queue($id, $type) + { + if (!$id || !$type) return $this->fail("参数缺失"); + $this->services->againDoQueue($id, $type); + return $this->success("后台程序已再次执行此批量任务"); + } + + /** + * 清除异常任务 + * @param $id + * @param $type + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function del_wrong_queue($id, $type) + { + if (!$id || !$type) return $this->fail("参数缺失"); + $res = $this->services->delWrongQueue($id, $type); + return $this->success($res ? "异常任务清除成功" : "数据无异常"); + } + + + /** + * 任务停止 + * @param $id + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function stop_wrong_queue($id) + { + if (!$id) return $this->fail("参数缺失"); + $queueInfo = $this->services->getQueueOne(['id' => $id]); + if (!$queueInfo) $this->fail('任务不存在'); + $this->services->delWrongQueue($id, $queueInfo['type'], false); + return $this->success("任务停止成功"); + } +} diff --git a/app/controller/supplier/system/Config.php b/app/controller/supplier/system/Config.php new file mode 100644 index 0000000..f5859a4 --- /dev/null +++ b/app/controller/supplier/system/Config.php @@ -0,0 +1,96 @@ + +// +---------------------------------------------------------------------- + +namespace app\controller\supplier\system; + + +use app\controller\supplier\AuthController; +use app\services\store\StoreConfigServices; +use app\services\system\config\SystemConfigServices; +use app\services\system\config\SystemConfigTabServices; +use think\facade\App; +use app\Request; + +/** + * Class Config + * @package app\controller\supplier\system + */ +class Config extends AuthController +{ + + /** + * Config constructor. + * @param App $app + * @param SystemConfigServices $services + */ + public function __construct(App $app, SystemConfigServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 获取门店配置 + * @param $type + * @param StoreConfigServices $services + * @return mixed + */ + public function getConfig($type, StoreConfigServices $services) + { + if (!isset(StoreConfigServices::CONFIG_TYPE[$type])) { + return $this->fail('类型不正确'); + } + return $this->success($services->getConfigAll(StoreConfigServices::CONFIG_TYPE[$type], 2, (int)$this->supplierId)); + } + + /** + * 保存数据 + * @param StoreConfigServices $services + * @return mixed + */ + public function save(StoreConfigServices $services) + { + $data = $this->request->post(); + $services->saveConfig($data,2, (int)$this->supplierId); + \crmeb\services\SystemConfigService::clear(); + return $this->success('修改成功'); + } + + /** + * 基础配置 + * @param Request $request + * @param StoreConfigServices $services + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function edit_basics(Request $request, StoreConfigServices $services) + { + $name = $this->request->param('name', ''); + if (!$name) { + return $this->fail('参数错误'); + } + $supplier_id = (int)$this->supplierId; + return $this->success($services->getFormBuildRule($name, 2, $supplier_id)); + } + + + /** + * @param string $type + * @return mixed + */ + public function getFormBuild(StoreConfigServices $services, string $type) + { + $supplier_id = (int)$this->supplierId; + return $this->success($services->getFormBuildRule($type, 2, $supplier_id)); + } +} diff --git a/app/controller/supplier/system/Supplier.php b/app/controller/supplier/system/Supplier.php new file mode 100644 index 0000000..9be759e --- /dev/null +++ b/app/controller/supplier/system/Supplier.php @@ -0,0 +1,111 @@ + +// +---------------------------------------------------------------------- + +namespace app\controller\supplier\system; + +use app\controller\supplier\AuthController; +use app\services\supplier\SystemSupplierServices; +use think\facade\App; + +/** + * 供应商控制器 + * Class Supplier + * @package app\controller\supplier + */ +class Supplier extends AuthController +{ + + /** + * 构造方法 + * Supplier constructor. + * @param App $app + * @param SystemSupplierServices $supplierServices + */ + public function __construct(App $app, SystemSupplierServices $supplierServices) + { + parent::__construct($app); + $this->services = $supplierServices; + } + + /** + * 获取供应商信息 + * @return void + */ + public function read() + { + $info = $this->services->getSupplierInfo((int)$this->supplierId); + return $this->success($info->toArray()); + } + + /** + * 更新供应商信息 + * @return void + */ + public function update() + { + $data = $this->request->postMore([ + ['supplier_name', ''], + ['name', ''], + ['phone', ''], + ['email', ''], + ['address', ''], + ['province', 0], + ['city', 0], + ['area', 0], + ['street', 0], + ['detailed_address', ''], + ]); + + $this->validate($data, \app\validate\supplier\SystemSupplierValidate::class, 'update'); + $data['address'] = str_replace([' ', '/', '\\'], '', $data['address']); + $data['detailed_address'] = str_replace([' ', '/', '\\'], '', $data['detailed_address']); + $this->services->update((int)$this->supplierId, $data); + return $this->success('保存成功'); + } + + /** + * 获取供应商财务信息 + * @return mixed + */ + public function getFinanceInfo() + { + $Info = $this->services->get((int)$this->supplierId); + if (!$Info) { + return app('json')->fail('供应商不存在'); + } + return app('json')->success($Info->toArray()); + } + + /** + * 设置供应商财务信息 + * @return mixed + */ + public function setFinanceInfo() + { + $data = $this->request->postMore([ + ['bank_code', ''], + ['bank_address', ''], + ['alipay_account', ''], + ['alipay_qrcode_url', ''], + ['wechat', ''], + ['wechat_qrcode_url', ''] + ]); + $Info = $this->services->get((int)$this->supplierId); + if (!$Info) { + return app('json')->fail('供应商不存在'); + } + if ($this->services->update($Info['id'], $data)) { + return app('json')->success('设置成功'); + } else { + return app('json')->fail('设置失败'); + } + } +} diff --git a/app/controller/supplier/system/SupplierAdmin.php b/app/controller/supplier/system/SupplierAdmin.php new file mode 100644 index 0000000..c881762 --- /dev/null +++ b/app/controller/supplier/system/SupplierAdmin.php @@ -0,0 +1,186 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\system; + +use app\controller\supplier\AuthController; +use app\services\supplier\LoginServices; +use app\services\supplier\SystemSupplierServices; +use app\services\system\admin\SystemAdminServices; +use think\facade\{App}; + +/** + * Class SystemAdmin + * @package app\controller\admin\v1\setting + */ +class SupplierAdmin extends AuthController +{ + /** + * @var LoginServices|null + */ + protected $services = NUll; + + /** + * @var SystemAdminServices|null + */ + protected $adminServices = NUll; + + /** + * SystemAdmin constructor. + * @param App $app + * @param SystemSupplierServices $services + * @param SystemAdminServices $adminServices + */ + public function __construct(App $app, SystemSupplierServices $services, SystemAdminServices $adminServices) + { + parent::__construct($app); + $this->services = $services; + $this->adminServices = $adminServices; + } + + /** + * 显示管理员资源列表 + * + * @return \think\Response + */ + public function index() + { + $where = [ + 'is_del' => 1, + 'admin_type' => 4, + 'relation_id' => $this->supplierId, + 'level' => 1 + ]; + return $this->success($this->adminServices->getAdminList($where)); + } + + /** + * 创建表单 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function create() + { + return $this->success($this->adminServices->createForm(0, '/admin')); + } + + /** + * 保存管理员 + * @return mixed + */ + public function save() + { + $data = $this->request->postMore([ + ['account', ''], + ['phone', ''], + ['conf_pwd', ''], + ['pwd', ''], + ['real_name', ''], + ['phone', ''], + ['roles', []], + ['status', 0], + ['head_pic', ''], + ]); + + $this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'supplier_save'); + $data['admin_type'] = 4; + $data['relation_id'] = $this->supplierId; + if ($this->adminServices->create($data)) { + return $this->success('添加成功'); + } else { + return $this->fail('添加失败'); + } + } + + /** + * 显示编辑资源表单页. + * + * @param int $id + * @return \think\Response + */ + public function edit(int $id) + { + if (!$id) { + return $this->fail('管理员信息读取失败'); + } + return $this->success($this->adminServices->updateForm(0, (int)$id, '/admin/')); + } + + /** + * 更新管理员 + * @param int $id + * @return mixed + */ + public function update(int $id) + { + $data = $this->request->postMore([ + ['account', ''], + ['phone', ''], + ['conf_pwd', ''], + ['pwd', ''], + ['real_name', ''], + ['phone', ''], + ['roles', []], + ['status', 0], + ['head_pic', ''], + ]); + + $this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'supplier_update'); + if ($this->adminServices->save($id, $data)) { + return $this->success('修改成功'); + } else { + return $this->fail('修改失败'); + } + } + + /** + * 管理员详情 + * @param int $id + * @return mixed + */ + public function read(int $id) + { + $info = $this->adminServices->get($id); + if (!$info) { + return $this->fail('获取失败'); + } + return $this->success($info->toArray()); + } + + /** + * 删除管理员 + * @param int $id + * @return void + */ + public function delete(int $id) + { + if (!$id) { + return $this->fail('删除失败,缺少参数'); + } + + if ($this->adminServices->update($id, ['is_del' => 1, 'status' => 0])) { + return $this->success('删除成功!'); + } else { + return $this->fail('删除失败'); + } + } + + /** + * 修改状态 + * @param $id + * @param $status + * @return mixed + */ + public function set_status($id, $status) + { + $this->adminServices->update((int)$id, ['status' => $status]); + return $this->success($status == 0 ? '关闭成功' : '开启成功'); + } +} diff --git a/app/controller/supplier/system/SupplierTicketPrint.php b/app/controller/supplier/system/SupplierTicketPrint.php new file mode 100644 index 0000000..a84fe74 --- /dev/null +++ b/app/controller/supplier/system/SupplierTicketPrint.php @@ -0,0 +1,66 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\system; + +use app\controller\supplier\AuthController; +use app\services\supplier\SupplierTicketPrintServices; +use think\facade\App; + +/** + * Class SupplierTicketPrint + * @package app\controller\supplier + */ + +class SupplierTicketPrint extends AuthController +{ + + /** + * 构造方法 + * Supplier constructor. + * @param App $app + * @param SupplierTicketPrintServices $services + */ + public function __construct(App $app, SupplierTicketPrintServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 获取打印信息 + * @param int $id + * @return void + */ + public function read() + { + return $this->success($this->services->getTicketInfo((int)$this->supplierId)); + } + + /** + * 更新打印信息 + * @param int $id + * @return void + */ + public function update() + { + $data = $this->request->postMore([ + ['develop_id', 0], + ['api_key', ''], + ['client_id', ''], + ['terminal_number', ''], + ['status', 0], + ]); + + $this->validate($data, \app\validate\supplier\SupplierTicketPrintValidate::class, 'update'); + $this->services->savePrintData((int)$this->supplierId, $data); + return $this->success('保存成功'); + } +} \ No newline at end of file diff --git a/app/controller/supplier/system/form/SystemForm.php b/app/controller/supplier/system/form/SystemForm.php new file mode 100644 index 0000000..e550d67 --- /dev/null +++ b/app/controller/supplier/system/form/SystemForm.php @@ -0,0 +1,76 @@ + +// +---------------------------------------------------------------------- + +namespace app\controller\supplier\system\form; + + +use app\controller\store\AuthController; +use app\services\system\form\SystemFormServices; +use think\facade\App; + +/** + * + * Class SystemForm + * @package app\controller\supplier\system\form + */ +class SystemForm extends AuthController +{ + + /** + * Diy constructor. + * @param App $app + * @param SystemFormServices $services + */ + public function __construct(App $app, SystemFormServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + + /* + * 所有系统表单 + */ + public function allSystemForm() + { + $data = $this->services->getFormList([], ['id', 'name']); + return $this->success($data['list'] ?? []); + } + + /** + * 获取一条数据 + * @param int $id + * @return mixed + */ + public function getInfo(int $id) + { + if (!$id) return $this->fail('数据不存在'); + [$type] = $this->request->postMore([ + ['type', 0], + ], true); + $info = $this->services->get($id); + if ($info) { + $info = $info->toArray(); + } else { + return $this->fail('数据不存在'); + } + $info['value'] = json_decode($info['value'], true); + if ($type == 1) {//处理表单数据 + $value = $info['value'] ?? []; + $info = $this->services->handleForm($value); + } + return $this->success(compact('info')); + } + + + + +} diff --git a/app/controller/supplier/user/User.php b/app/controller/supplier/user/User.php new file mode 100644 index 0000000..f02085c --- /dev/null +++ b/app/controller/supplier/user/User.php @@ -0,0 +1,93 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\supplier\user; + +use app\services\user\UserSpreadServices; +use think\facade\App; +use app\services\user\UserServices; +use app\controller\supplier\AuthController; +use app\services\product\product\StoreProductLogServices; + +class User extends AuthController +{ + /** + * user constructor. + * @param App $app + * @param UserServices $services + */ + public function __construct(App $app, UserServices $services) + { + parent::__construct($app); + $this->services = $services; + } + + /** + * 显示用户信息 + * + * @param int $id + * @return \think\Response + */ + public function read($id) + { + if (is_string($id)) { + $id = (int)$id; + } + return $this->success($this->services->read($id)); + } + + /** + * 获取单个用户信息 + * @param $id 用户id + * @return mixed + */ + public function oneUserInfo($id) + { + $data = $this->request->getMore([ + ['type', ''], + ]); + $id = (int)$id; + if ($data['type'] == '') return $this->fail('缺少参数'); + return $this->success($this->services->oneUserInfo($id, $data['type'])); + } + + /** + * 商品浏览记录 + * @param $id + * @param StoreProductLogServices $services + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function visitList($id, StoreProductLogServices $services) + { + $where['uid'] = (int)$id; + $where['type'] = 'visit'; + return app('json')->success($services->getList($where, 'product_id')); + } + + /** + * 获取推广人记录 + * @param $id + * @param UserSpreadServices $services + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function spreadList($id, UserSpreadServices $services) + { + $where['store_id'] = 0; + $where['staff_id'] = 0; + $where['uid'] = $id; + return app('json')->success($services->getSpreadList($where, '*', ['spreadUser', 'admin'], false)); + } +} diff --git a/app/dao/order/StoreOrderPromotionsDao.php b/app/dao/order/StoreOrderPromotionsDao.php new file mode 100644 index 0000000..3bd8724 --- /dev/null +++ b/app/dao/order/StoreOrderPromotionsDao.php @@ -0,0 +1,56 @@ + +// +---------------------------------------------------------------------- + +namespace app\dao\order; + + +use app\dao\BaseDao; +use app\model\order\StoreOrderPromotions; + +/** + * 订单详情 + * Class StoreOrderPtomotionsDao + * @package app\dao\order + * @method saveAll(array $data) + */ +class StoreOrderPromotionsDao extends BaseDao +{ + /** + * 设置模型 + * @return string + */ + protected function setModel(): string + { + return StoreOrderPromotions::class; + } + + + /** + * 获取购物车详情列表 + * @param array $where + * @param string $field + * @param array $with + * @param string $group + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getPromotionsDetailList(array $where, string $field = '*', array $with = [], string $group = '') + { + return $this->search($where)->field($field)->when($with, function($query) use($with) { + $query->with($with); + })->when($group, function($query) use($group) { + $query->group($group); + })->select()->toArray(); + } + +} diff --git a/app/dao/order/StoreOrderWriteoffDao.php b/app/dao/order/StoreOrderWriteoffDao.php new file mode 100644 index 0000000..cc4b480 --- /dev/null +++ b/app/dao/order/StoreOrderWriteoffDao.php @@ -0,0 +1,77 @@ + +// +---------------------------------------------------------------------- + +namespace app\dao\order; + + +use app\dao\BaseDao; +use app\model\order\StoreOrderWriteoff; + +/** + * 订单核销 + * Class StoreOrderWriteoffDao + * @package app\dao\order + * @method saveAll(array $data) + */ +class StoreOrderWriteoffDao extends BaseDao +{ + /** + * 设置模型 + * @return string + */ + protected function setModel(): string + { + return StoreOrderWriteoff::class; + } + + /** + * @param array $where + * @return \crmeb\basic\BaseModel|mixed|\think\Model + */ + public function search(array $where = []) + { + return parent::search($where) + ->when(isset($where['keyword']) && $where['keyword'] , function($query) use ($where) { + $query->where(function ($q) use ($where) { + $q->whereLike('uid|oid|relation_id|staff_id|product_id', '%' . $where['keyword'] . '%') + ->whereOr('uid', 'IN', function ($user) use ($where) { + $user->name('user')->field('id')->whereLike('uid|phone|nickname', '%' . $where['keyword'] . '%'); + })->whereOr('product_id', 'IN', function ($product) use ($where) { + $product->name('store_product')->field('id')->whereLike('store_name|keyword', '%' . $where['keyword'] . '%'); + })->whereOr('oid', 'IN', function ($order) use ($where) { + $order->name('store_order')->field('id')->whereLike('order_id|uid|user_phone|staff_id', '%' . $where['keyword'] . '%'); + }); + }); + }); + } + + /** + * 获取核销列表 + * @param array $where + * @param string $field + * @param int $page + * @param int $limit + * @param array $with + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = []) + { + return $this->search($where)->field($field) + ->when($with, function ($query) use ($with) { + $query->with($with); + })->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) { + $query->page($page, $limit); + })->order('id desc')->select()->toArray(); + } +} diff --git a/app/dao/product/product/StoreProductCouponDao.php b/app/dao/product/product/StoreProductCouponDao.php new file mode 100644 index 0000000..75a52b7 --- /dev/null +++ b/app/dao/product/product/StoreProductCouponDao.php @@ -0,0 +1,46 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\dao\product\product; + +use app\dao\BaseDao; +use app\model\product\product\StoreProductCoupon; + +/** + * + * Class StoreProductCouponDao + * @package app\dao\coupon + */ +class StoreProductCouponDao extends BaseDao +{ + + /** + * 设置模型 + * @return string + */ + protected function setModel(): string + { + return StoreProductCoupon::class; + } + + /** + * 获取商品关联优惠卷 + * @param array $product_ids + * @param string $field + * @return int|void + */ + public function getProductCoupon(array $product_ids, string $field = '*') + { + return $this->search(['product_id' => $product_ids])->field($field)->select()->toArray(); + } + +} diff --git a/app/dao/product/product/StoreProductUnitDao.php b/app/dao/product/product/StoreProductUnitDao.php new file mode 100644 index 0000000..62b098f --- /dev/null +++ b/app/dao/product/product/StoreProductUnitDao.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- + +namespace app\dao\product\product; + +use app\dao\BaseDao; +use app\model\product\product\StoreProductUnit; + +/** + * 商品单位dao + * Class StoreProductUnitDao + * @package app\dao\product\product + */ +class StoreProductUnitDao extends BaseDao +{ + /** + * 设置模型 + * @return string + */ + protected function setModel(): string + { + return StoreProductUnit::class; + } + + /** + * 获取单位列表 + * @param array $where + * @param string $field + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0) + { + return $this->search($where)->field($field) + ->when($page && $limit, function ($query) use ($page, $limit) { + $query->page($page, $limit); + })->order('sort desc,id desc')->select()->toArray(); + } +} diff --git a/app/dao/system/config/SystemConfigTabDao.php b/app/dao/system/config/SystemConfigTabDao.php new file mode 100644 index 0000000..1a5e5ea --- /dev/null +++ b/app/dao/system/config/SystemConfigTabDao.php @@ -0,0 +1,66 @@ + +// +---------------------------------------------------------------------- + +namespace app\dao\system\config; + + +use app\dao\BaseDao; +use app\model\system\config\SystemConfigTab; + +/** + * 配置分类 + * Class SystemConfigTabDao + * @package app\dao\system\config + */ +class SystemConfigTabDao extends BaseDao +{ + /** + * 设置模型 + * @return string + */ + protected function setModel(): string + { + return SystemConfigTab::class; + } + + /** + * 获取配置分类 + * @param array $searchWhere + * @param array $field + * @param array $where + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getConfigTabAll(array $searchWhere, array $field = ['*'], array $where = []) + { + return $this->search($searchWhere)->when(count($where), function ($query) use ($where) { + $query->where($where); + })->field($field)->order('sort desc,id asc')->select()->toArray(); + } + + /** + * 配置分类列表 + * @param array $where + * @param int $page + * @param int $limit + * @return \think\Collection + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getConfgTabList(array $where, int $page, int $limit) + { + return $this->search($where)->order('sort desc,id asc')->page($page, $limit)->select(); + } + +} diff --git a/app/jobs/product/ProductBatchJob.php b/app/jobs/product/ProductBatchJob.php new file mode 100644 index 0000000..7faf70a --- /dev/null +++ b/app/jobs/product/ProductBatchJob.php @@ -0,0 +1,136 @@ + +// +---------------------------------------------------------------------- + +namespace app\jobs\product; + + +use app\services\product\product\StoreProductBatchProcessServices; +use crmeb\basic\BaseJobs; +use crmeb\traits\QueueTrait; + +/** + * 商品批量任务队列 + * Class ProductBatchJob + * @package app\jobs\product + */ +class ProductBatchJob extends BaseJobs +{ + use QueueTrait; + + /** + * @return mixed + */ + public static function queueName() + { + $default = config('queue.default'); + return config('queue.connections.' . $default . '.batch_queue'); + } + + + /** + * 商品批量队列 + * @param $type + * @param $ids + * @param $data + * @param $isBatch + * @return bool + */ + public function productBatch($type, $ids, $data, $isBatch = false) + { + if (!$type || !$ids || !$data) { + return true; + } + //是否批量多个修改 + if ($isBatch) { + $length = 30; + } else { + $length = 100; + } + //拆分大数组 分批加入二级队列 + $idsArr = array_chunk($ids, $length); + foreach ($idsArr as $ids) { + //加入分批队列 + self::dispatchDo('chunkProductBatch', [$type, $ids, $data, $isBatch]); + } + return true; + } + + /** + * 拆分分批队列 + * @param $type + * @param $ids + * @param $data + * @param $isBatch + * @return bool + */ + public function chunkProductBatch($type, $ids, $data, $isBatch = false) + { + if (!$type || !$ids || !$data) { + return true; + } + //是否批量多个修改 + if ($isBatch) { + self::dispatchDo('runProductBatch', [$type, $ids, $data]); + } else {//拆分id,单个队列执行 + foreach ($ids as $id) { + self::dispatchDo('runProductBatch', [$type, $id, $data]); + } + } + return true; + } + + /** + * 实际执行商品操作队列 + * @param $type + * @param $ids + * @param $data + * @return bool + */ + public function runProductBatch($type, $id, $data) + { + if (!is_array($id)) { + $id = (int)$id; + } + if (!$type || !$id || !$data) { + return true; + } + try { + /** @var StoreProductBatchProcessServices $batchProcessServices */ + $batchProcessServices = app()->make(StoreProductBatchProcessServices::class); + switch ($type) { + case 1://分类 + $batchProcessServices->setPrdouctCate($id, $data); + break; + case 4://购买即送积分、优惠券 + $batchProcessServices->setGiveIntegralCoupon($id, $data); + break; + case 2://商品标签 + case 3://物流设置 + case 5://关联用户标签 + case 6://活动推荐 + case 7://自定义留言 + case 8://运费设置 + case 9://商品展示 + $batchProcessServices->runBatch($id, $data, (int)$type); + break; + default: + break; + } + } catch (\Throwable $e) { + response_log_write([ + 'message' => '批量操作商品,type:' . $type . ';状态失败' . ';参数:' . json_encode(['id' => $id, 'data' => $data]) . ',失败原因:' . $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ]); + } + return true; + } +} diff --git a/app/jobs/product/ProductCouponJob.php b/app/jobs/product/ProductCouponJob.php new file mode 100644 index 0000000..11cd2d7 --- /dev/null +++ b/app/jobs/product/ProductCouponJob.php @@ -0,0 +1,69 @@ + +// +---------------------------------------------------------------------- + +namespace app\jobs\product; + + +use app\services\product\product\StoreProductCouponServices; +use crmeb\basic\BaseJobs; +use crmeb\traits\QueueTrait; +use think\facade\Log; + +/** + * 商品关联优惠券 + * Class ProductCouponJob + * @package app\jobs\product + */ +class ProductCouponJob extends BaseJobs +{ + use QueueTrait; + + /** + * @param $orderInfo + * @return bool + */ + public function doJob($orderInfo) + { + if (!$orderInfo) return true; + try { + /** @var StoreProductCouponServices $storeProductCouponServices */ + $storeProductCouponServices = app()->make(StoreProductCouponServices::class); + $storeProductCouponServices->giveOrderProductCoupon((int)$orderInfo['uid'], $orderInfo['id']); + } catch (\Throwable $e) { + Log::error('赠送订单商品关联优惠券发生错误,错误原因:' . $e->getMessage()); + } + return true; + } + + /** + * 设置保存商品关联优惠券 + * @param $id + * @param $coupon_ids + * @return bool|void + */ + public function setProductCoupon($id, $coupon_ids) + { + if (!$id) return true; + try { + /** @var StoreProductCouponServices $storeProductCouponServices */ + $storeProductCouponServices = app()->make(StoreProductCouponServices::class); + $storeProductCouponServices->setCoupon($id, $coupon_ids); + } catch (\Throwable $e) { + response_log_write([ + 'message' => '设置保存商品关联优惠券发生错误,错误原因:' . $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ]); + } + return true; + } + +} diff --git a/app/jobs/product/ProductRelationJob.php b/app/jobs/product/ProductRelationJob.php new file mode 100644 index 0000000..0cdee42 --- /dev/null +++ b/app/jobs/product/ProductRelationJob.php @@ -0,0 +1,52 @@ + +// +---------------------------------------------------------------------- + +namespace app\jobs\product; + + +use app\services\product\product\StoreProductRelationServices; +use crmeb\basic\BaseJobs; +use crmeb\traits\QueueTrait; + +/** + * 商品关联关系 + * Class ProductRelationJob + * @package app\jobs\product + */ +class ProductRelationJob extends BaseJobs +{ + use QueueTrait; + + /** + * @param int $id + * @param array $relation_id + * @param int $type + * @param int $is_show + * @return bool + */ + public function doJob(int $id, array $relation_id, int $type = 1, int $is_show = 1) + { + try { + /** @var StoreProductRelationServices $storeProductRelationServices */ + $storeProductRelationServices = app()->make(StoreProductRelationServices::class); + //商品关联 + $storeProductRelationServices->saveRelation($id, $relation_id, $type, $is_show); + } catch (\Throwable $e) { + response_log_write([ + 'message' => '写入商品关联[type:' . $type . ']发生错误,错误原因:' . $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine() + ]); + } + return true; + } + +} diff --git a/app/model/order/StoreOrderPromotions.php b/app/model/order/StoreOrderPromotions.php new file mode 100644 index 0000000..bab169c --- /dev/null +++ b/app/model/order/StoreOrderPromotions.php @@ -0,0 +1,99 @@ + +// +---------------------------------------------------------------------- + +namespace app\model\order; + +use crmeb\basic\BaseModel; +use crmeb\traits\ModelTrait; +use app\model\activity\promotions\StorePromotions; +use think\Model; + +/** + * 订单优惠活动记录Model + * Class SoreOrderPromotions + * @package app\model\order + */ +class StoreOrderPromotions extends BaseModel +{ + use ModelTrait; + + /** + * 数据表主键 + * @var string + */ + protected $pk = 'id'; + + /** + * 模型名称 + * @var string + */ + protected $name = 'store_order_promotions'; + + + /** + * 一对一关联优惠活动 + * @return \think\model\relation\hasMany + */ + public function promotions() + { + return $this->hasOne(StorePromotions::class, 'id', 'promotions_id'); + } + + /** + * 订单ID搜索器 + * @param Model $query + * @param $value + * @param $data + */ + public function searchOidAttr($query, $value, $data) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('oid', $value); + } else { + $query->where('oid', $value); + } + } + } + + /** + * UID搜索器 + * @param Model $query + * @param $value + */ + public function searchUidIdAttr($query, $value) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('uid', $value); + } else { + $query->where('uid', $value); + } + } + } + + /** + * 优惠活动ID搜索器 + * @param Model $query + * @param $value + */ + public function searchPromotionsIdAttr($query, $value) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('promotions_id', $value); + } else { + $query->where('promotions_id', $value); + } + } + } + +} diff --git a/app/model/order/StoreOrderWriteoff.php b/app/model/order/StoreOrderWriteoff.php new file mode 100644 index 0000000..6617173 --- /dev/null +++ b/app/model/order/StoreOrderWriteoff.php @@ -0,0 +1,183 @@ + +// +---------------------------------------------------------------------- + +namespace app\model\order; + +use app\model\store\SystemStoreStaff; +use app\common\model\user\User; +use crmeb\basic\BaseModel; +use crmeb\traits\ModelTrait; +use think\Model; + +/** + * 订单核销记录Model + * Class StoreOrderWriteoff + * @package app\model\order + */ +class StoreOrderWriteoff extends BaseModel +{ + use ModelTrait; + + /** + * 模型名称 + * @var string + */ + protected $name = 'store_order_writeoff'; + + + /** + * 获取领取人名称头像 + * @return \think\model\relation\HasOne + */ + public function userInfo() + { + return $this->hasOne(User::class, 'uid', 'uid')->field('uid,nickname,avatar,phone')->bind(['nickname', 'avatar', 'phone']); + } + + /** + * 订单信息 + * @return \think\model\relation\HasOne + */ + public function orderInfo() + { + return $this->hasOne(StoreOrder::class, 'id', 'oid'); + } + + /** + * 订单商品信息 + * @return \think\model\relation\HasOne + */ + public function cartInfo() + { + return $this->hasOne(StoreOrderCartInfo::class, 'id', 'order_cart_id'); + } + + /** + * 店员信息 + * @return \think\model\relation\HasOne + */ + public function staffInfo() + { + return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->field('id,store_id,staff_name')->bind(['staff_name']); + } + + /** + * 订单ID搜索器 + * @param Model $query + * @param $value + * @param $data + */ + public function searchOidAttr($query, $value, $data) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('oid', $value); + } else { + $query->where('oid', $value); + } + } + } + + /** + * UID搜索器 + * @param Model $query + * @param $value + */ + public function searchUidAttr($query, $value) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('uid', $value); + } else { + $query->where('uid', $value); + } + } + } + + /** + * 商品类型搜索器 + * @param Model $query + * @param $value + */ + public function searchTypeAttr($query, $value) + { + if (is_array($value)) { + if ($value) $query->whereIn('type', $value); + } else { + if ($value !== '') $query->where('type', $value); + } + } + + /** + * 关联门店ID、供应商ID搜索器 + * @param Model $query + * @param $value + */ + public function searchRelationIdAttr($query, $value) + { + if (is_array($value)) { + if ($value) $query->whereIn('relation_id', $value); + } else { + if ($value !== '') $query->where('relation_id', $value); + } + } + + /** + * product_id搜索器 + * @param Model $query + * @param $value + */ + public function searchProductIdAttr($query, $value) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('product_id', $value); + } else { + $query->where('product_id', $value); + } + } + } + + /** + * 订单商品ID搜索器 + * @param Model $query + * @param $value + * @param $data + */ + public function searchOrderCartIdAttr($query, $value, $data) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('order_cart_id', $value); + } else { + $query->where('order_cart_id', $value); + } + } + } + + /** + * staff_id搜索器 + * @param Model $query + * @param $value + */ + public function searchStaffIdAttr($query, $value) + { + if ($value) { + if (is_array($value)) { + $query->whereIn('staff_id', $value); + } else { + $query->where('staff_id', $value); + } + } + } + + +} diff --git a/app/model/product/product/StoreProductCoupon.php b/app/model/product/product/StoreProductCoupon.php new file mode 100644 index 0000000..5b70763 --- /dev/null +++ b/app/model/product/product/StoreProductCoupon.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- + +namespace app\model\product\product; + + +use crmeb\basic\BaseModel; +use crmeb\traits\ModelTrait; + +/** + * Class StoreProductCoupon + * @package app\model\product\product + */ +class StoreProductCoupon extends BaseModel +{ + use ModelTrait; + + /** + * 数据表主键 + * @var string + */ + protected $pk = 'id'; + + /** + * 模型名称 + * @var string + */ + protected $name = 'store_product_coupon'; + + + public function searchProductIdAttr($query, $value) + { + if(is_array($value)) + $query->whereIn('product_id',$value); + else + $query->where('product_id',$value); + } + +} diff --git a/app/model/product/product/StoreProductUnit.php b/app/model/product/product/StoreProductUnit.php new file mode 100644 index 0000000..8e124c1 --- /dev/null +++ b/app/model/product/product/StoreProductUnit.php @@ -0,0 +1,130 @@ + +// +---------------------------------------------------------------------- + +namespace app\model\product\product; + +use crmeb\basic\BaseModel; +use crmeb\traits\ModelTrait; +use think\Model; + + +/** + * 商品单位 + * Class StoreProductUnit + * @package app\model\product\product + */ +class StoreProductUnit extends BaseModel +{ + + use ModelTrait; + + /** + * 数据表主键 + * @var string + */ + protected $pk = 'id'; + + /** + * 模型名称 + * @var string + */ + protected $name = 'store_product_unit'; + + /** + * 单位名称 + * @param $query + * @param $value + */ + public function searchNameAttr($query, $value) + { + if ($value !== '') $query->whereLike('id|name', '%' . $value . '%'); + } + + /** + * 门店ID + * @param $query + * @param $value + */ + public function searchStoreIdAttr($query, $value) + { + if ($value !== '') { + if ($value == -1) {//所有门店 + $query->where('store_id', '>', 0); + } else { + $query->where('store_id', $value); + } + } + } + + /** + * 商户搜索器 + * @param Model $query + * @param $value + */ + public function searchTypeAttr($query, $value) + { + if (is_array($value)) { + if ($value) $query->whereIn('type', $value); + } else { + if ($value !== '') $query->where('type', $value); + } + } + + /** + * 关联门店ID、供应商ID搜索器 + * @param Model $query + * @param $value + */ + public function searchRelationIdAttr($query, $value) + { + if (is_array($value)) { + if ($value) $query->whereIn('relation_id', $value); + } else { + if ($value !== '') $query->where('relation_id', $value); + } + } + + /** + * 供应商 + * @param Model $query + * @param $value + */ + public function searchSupplierIdAttr($query, $value) + { + if (is_array($value)) { + if ($value) $query->whereIn('relation_id', $value)->where('type', 2); + } else { + if ($value !== '') $query->where('relation_id', $value)->where('type', 2); + } + } + + + /** + * 是否显示搜索器 + * @param $query + * @param $value + */ + public function searchStatusAttr($query, $value) + { + if ($value !== '') $query->where('status', $value); + } + + /** + * 是否删除搜索器 + * @param $query + * @param $value + */ + public function searchIsDelAttr($query, $value) + { + if ($value !== '') $query->where('is_del', $value); + } + +} diff --git a/app/model/system/config/SystemConfigTab.php b/app/model/system/config/SystemConfigTab.php new file mode 100644 index 0000000..a30f891 --- /dev/null +++ b/app/model/system/config/SystemConfigTab.php @@ -0,0 +1,99 @@ + +// +---------------------------------------------------------------------- + +namespace app\model\system\config; + +use crmeb\basic\BaseModel; +use crmeb\traits\ModelTrait; +use think\Model; + +/** + * 配置分类模型 + * Class SystemConfigTab + * @package app\model\system\config + */ +class SystemConfigTab extends BaseModel +{ + use ModelTrait; + + /** + * 数据表主键 + * @var string + */ + protected $pk = 'id'; + + /** + * 模型名称 + * @var string + */ + protected $name = 'system_config_tab'; + + /** + * 状态搜索器 + * @param Model $query + * @param $value + */ + public function searchStatusAttr($query, $value) + { + if ($value != '') { + $query->where('status', $value); + } + } + + /** + * pid搜索器 + * @param Model $query + * @param $value + */ + public function searchPidAttr($query, $value) + { + if (is_array($value)) { + $query->whereIn('pid', $value); + } else { + $value && $query->where('pid', $value); + } + } + + /** + * 类型搜索器 + * @param Model $query + * @param $value + */ + public function searchTypeAttr($query, $value) + { + $query->where('status', 1); + if ($value > -1) { + $query->where(['type' => $value, 'pid' => 0]); + } + } + + /** + * 分类名称搜索器 + * @param Model $query + * @param $value + */ + public function searchTitleAttr($query, $value) + { + $query->whereLike('title', '%' . $value . '%'); + } + + /** + * @param $query + * @param $value + */ + public function searchIsStoreAttr($query, $value) + { + if ($value !== '') { + $query->where('is_store', $value); + } + } + +} diff --git a/app/services/order/StoreOrderPromotionsServices.php b/app/services/order/StoreOrderPromotionsServices.php new file mode 100644 index 0000000..c79a5c6 --- /dev/null +++ b/app/services/order/StoreOrderPromotionsServices.php @@ -0,0 +1,206 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\order; + +use app\dao\order\StoreOrderPromotionsDao; +use app\services\BaseServices; +use crmeb\traits\ServicesTrait; +use think\exception\ValidateException; + +/** + * Class StoreOrderPromotionsServices + * @package app\services\order + * @mixin StoreOrderPromotionsDao + */ +class StoreOrderPromotionsServices extends BaseServices +{ + + use ServicesTrait; + + /** + * StoreOrderPromotionsServices constructor. + * @param StoreOrderPromotionsDao $dao + */ + public function __construct(StoreOrderPromotionsDao $dao) + { + $this->dao = $dao; + } + + /** + * 保存订单优惠详情 + * @param $oid + * @param array $cartInfo + * @param $uid + * @return int + */ + public function setPromotionsDetail(int $uid, int $oid, array $cartList, array $promotionsList) + { + $group = []; + if ($promotionsList) { + $time = time(); + foreach ($cartList as $key => $cart) { + foreach ($promotionsList as $promotions) { + $details = $promotions['details'] ?? []; + $unique = $cart['product_attr_unique'] ?? ''; + if ($details && isset($details[$unique]['promotions_true_price'])) { + $group[] = [ + 'oid' => $oid, + 'uid' => $uid, + 'product_id' => $cart['productInfo']['id'], + 'promotions_id' => $promotions['id'], + 'promotions_price' => bcmul((string)($details[$unique]['promotions_true_price'] ?? 0), (string)$cart['cart_num'], 2), + 'add_time' => $time + ]; + } + } + } + } + if ($group) { + return $this->dao->saveAll($group); + } + return true; + } + + /** + * 获取订单商品实际参与优惠活动 以及优惠金额 + * @param int $oid + * @return array + */ + public function getOrderPromotionsDetail(int $oid) + { + $result = $this->dao->getPromotionsDetailList(['oid' => $oid], '*,sum(`promotions_price`) as promotions_price', ['promotions' => function($query) { + $query->field('id,name,title,desc')->bind([ + 'promotions_type' => 'promotions_type', + 'name' => 'name', + 'title' => 'title', + 'desc' => 'desc' + ]); + }], 'promotions_id'); + if ($result) { + $typeArr = array_column($result, 'promotions_type'); + array_multisort($typeArr, SORT_ASC, $result); + } + return $result; + } + + /** + * 拆分订单同步拆分优惠活动记录 + * @param int $oid + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function splitOrderPromotions(int $oid) + { + /** @var StoreOrderServices $storeOrderServices */ + $storeOrderServices = app()->make(StoreOrderServices::class); + $orderInfo = $storeOrderServices->getOne(['id' => $oid, 'is_del' => 0]); + if (!$orderInfo) { + throw new ValidateException('订单不存在'); + } + $promotions_give = []; + $promotions = []; + if (isset($orderInfo['promotions_give']) && $orderInfo['promotions_give']) { + $promotions_give = is_string($orderInfo['promotions_give']) ? json_decode($promotions_give, true) : $orderInfo['promotions_give']; + } + $promotions = $promotions_give['promotions'] ?? []; + $pid = $orderInfo['pid'] > 0 ? $orderInfo['pid'] : $orderInfo['id']; + //查询优惠记录 + $orderPromotions = $this->dao->getPromotionsDetailList(['order_id' => $oid]); + //查询子订单 + $spliteOrder = $storeOrderServices->getColumn(['pid' => $pid, 'is_system_del' => 0], 'id,order_id'); + if ($spliteOrder && $orderPromotions && $promotions) { + /** @var StoreOrderCartInfoServices $storeOrderCartInfoServices */ + $storeOrderCartInfoServices = app()->make(StoreOrderCartInfoServices::class); + $data_all = $data = []; + $data['uid'] = $orderInfo['uid']; + $data['add_time'] = time(); + foreach ($spliteOrder as $order) { + $cartInfo = $storeOrderCartInfoServices->getColumn(['oid' => $order['id']], 'id,product_id,cart_num,cart_info'); + if (!$cartInfo) { + continue; + } + $data['oid'] = $order['id']; + foreach ($cartInfo as $key => $cart) { + $data['product_id'] = $cart['product_id']; + $_info = is_string($cart['cart_info']) ? json_decode($cart['cart_info'], true) : $cart['cart_info']; + $unique = $_info['product_attr_unique'] ?? ''; + foreach ($promotions as $key => $info) { + if (isset($info['details'][$unique])) { + $data['promotions_id'] = $info['id']; + $data['promotions_price'] = floatval(bcmul((string)($info['details'][$unique]['promotions_true_price'] ?? 0), (string)$cart['cart_num'], 2)); + $data_all[] = $data; + } + } + } + } + if ($data_all) { + $this->transaction(function () use ($data_all, $spliteOrder) { + $this->dao->delete(['oid' => array_column($spliteOrder, 'id')]); + $this->dao->saveAll($data_all); + + }); + } + } + return true; + } + + + /** + * 申请退款订单优惠详情处理 + * @param int $oid + * @param array $cartInfo + * @return bool + */ + public function applyRefundOrderPromotions(int $oid, array $cartInfo = []) + { + /** @var StoreOrderServices $storeOrderServices */ + $storeOrderServices = app()->make(StoreOrderServices::class); + $orderInfo = $storeOrderServices->getOne(['id' => $oid, 'is_del' => 0]); + if (!$orderInfo) { + return []; + } + $promotions_give = []; + $promotions = []; + if (isset($orderInfo['promotions_give']) && $orderInfo['promotions_give']) { + $promotions_give = is_string($orderInfo['promotions_give']) ? json_decode($promotions_give, true) : $orderInfo['promotions_give']; + } + $promotions = $promotions_give['promotions'] ?? []; + if (!$cartInfo || !$promotions) { + return []; + } + $data_all = []; + foreach ($promotions as $key => $info) { + $data = []; + foreach ($cartInfo as $key => $cart) { + if (isset($info['details'][$cart['product_id']])) { + $data['promotions_id'] = $info['id']; + $data['promotions_type'] = $info['promotions_type']; + $data['name'] = $info['name']; + $data['title'] = $info['title']; + $data['desc'] = $info['desc']; + $data['promotions_price'] = bcadd((string)($data['promotions_price'] ?? 0), (string)bcmul((string)($info['details'][$cart['product_id']]['promotions_true_price'] ?? 0), (string)$cart['cart_num'], 2), 2); + } + } + if ($data) { + $data_all[] = $data; + } + } + if ($data_all) { + $typeArr = array_column($data_all, 'promotions_type'); + array_multisort($typeArr, SORT_ASC, $data_all); + } + return $data_all; + } + +} diff --git a/app/services/order/StoreOrderWriteOffServices.php b/app/services/order/StoreOrderWriteOffServices.php new file mode 100644 index 0000000..067cdd8 --- /dev/null +++ b/app/services/order/StoreOrderWriteOffServices.php @@ -0,0 +1,232 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\order; + + +use app\dao\order\StoreOrderDao; +use app\dao\order\StoreOrderWriteoffDao; +use app\services\activity\integral\StoreIntegralOrderServices; +use app\services\activity\integral\StoreIntegralOrderStatusServices; +use app\services\activity\combination\StorePinkServices; +use app\services\BaseServices; +use app\services\pay\PayServices; +use app\services\store\SystemStoreServices; +use app\services\store\SystemStoreStaffServices; +use app\services\store\DeliveryServiceServices; +use app\services\supplier\SystemSupplierServices; +use app\services\user\UserServices; +use think\exception\ValidateException; + +/** + * 核销订单 + * Class StoreOrderWriteOffServices + * @package app\sservices\order + * @mixin StoreOrderDao + */ +class StoreOrderWriteOffServices extends BaseServices +{ + protected $orderDao; + + /** + * 构造方法 + * @param StoreOrderWriteoffDao $dao + * @param StoreOrderDao $orderDao + */ + public function __construct(StoreOrderWriteoffDao $dao, StoreOrderDao $orderDao) + { + $this->dao = $dao; + $this->orderDao = $orderDao; + } + + /** + * 获取核销列表 + * @param $where + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function writeOffList($where) + { + [$page, $limit] = $this->getPageValue(); + + $list = $this->dao->getList($where, '*', $page, $limit, [ + 'userInfo', + 'staffInfo', + 'orderInfo' => function ($query) { + $query->field('id,order_id,pay_type'); + }, + 'cartInfo' => function ($query) { + $query->field('id,cart_info'); + }, + ]); + $count = $this->dao->count($where); + if ($list) { + $supplierIds = $storeIds = []; + foreach ($list as $value) { + switch ($value['type']) { + case 0: + break; + case 1://门店 + $storeIds[] = $value['relation_id']; + break; + case 2://供应商 + $supplierIds[] = $value['relation_id']; + break; + } + } + $supplierIds = array_unique($supplierIds); + $storeIds = array_unique($storeIds); + $supplierList = $storeList = []; + if ($supplierIds) { + /** @var SystemSupplierServices $supplierServices */ + $supplierServices = app()->make(SystemSupplierServices::class); + $supplierList = $supplierServices->getColumn([['id', 'in', $supplierIds], ['is_del', '=', 0]], 'id,supplier_name', 'id'); + } + if ($storeIds) { + /** @var SystemStoreServices $storeServices */ + $storeServices = app()->make(SystemStoreServices::class); + $storeList = $storeServices->getColumn([['id', 'in', $storeIds], ['is_del', '=', 0]], 'id,name', 'id'); + } + foreach ($list as &$item) { + $cartInfo = $item['cartInfo'] ?? []; + $cartInfo = is_string($cartInfo['cart_info']) ? json_decode($cartInfo['cart_info'], true) : $cartInfo['cart_info']; + $item['productInfo'] = $cartInfo['productInfo'] ?? []; + $orderInfo = $item['orderInfo'] ?? []; + $item['order_id'] = $orderInfo['order_id'] ?? ''; + $item['pay_type'] = $orderInfo['pay_type'] ?? ''; + switch ($item['pay_type']) { + case PayServices::WEIXIN_PAY: + $item['pay_type_name'] = '微信支付'; + break; + case PayServices::YUE_PAY: + $item['pay_type_name'] = '余额支付'; + break; + case PayServices::OFFLINE_PAY: + $item['pay_type_name'] = '线下支付'; + break; + case PayServices::ALIAPY_PAY: + $item['pay_type_name'] = '支付宝支付'; + break; + case PayServices::CASH_PAY: + $item['pay_type_name'] = '现金支付'; + break; + default: + $item['pay_type_name'] = '其他支付'; + break; + } + $item['plate_name'] = '平台'; + switch ($item['type']) { + case 0: + $item['plate_name'] = '平台'; + break; + case 1://门店 + $item['plate_name'] = '门店:' . ($storeList[$item['relation_id']]['name'] ?? ''); + break; + case 2://供应商 + $item['plate_name'] = '供应商:' . ($supplierList[$item['relation_id']]['supplier_name'] ?? ''); + break; + } + } + } + + return compact('list', 'count'); + } + + /** + * 保存核销记录 + * @param int $oid + * @param array $cartIds + * @param array $data + * @param array $orderInfo + * @param array $cartInfo + * @return bool + */ + public function saveWriteOff(int $oid, array $cartIds = [], array $data = [], array $orderInfo = [], array $cartInfo = []) + { + if (!$oid) { + throw new ValidateException('缺少核销订单信息'); + } + if (!$orderInfo) { + /** @var StoreOrderServices $storeOrderServices */ + $storeOrderServices = app()->make(StoreOrderServices::class); + $orderInfo = $storeOrderServices->get($oid); + } + if (!$orderInfo) { + throw new ValidateException('核销订单不存在'); + } + $orderInfo = is_object($orderInfo) ? $orderInfo->toArray() : $orderInfo; + if (!$cartInfo) { + /** @var StoreOrderCartInfoServices $cartInfoServices */ + $cartInfoServices = app()->make(StoreOrderCartInfoServices::class); + if ($cartIds) {//商城存在部分核销 + $ids = array_unique(array_column($cartIds, 'cart_id')); + $cartIds = array_combine($ids, $cartIds); + //订单下原商品信息 + $cartInfo = $cartInfoServices->getCartColunm(['oid' => $orderInfo['id'], 'cart_id' => $ids], '*', 'cart_id'); + } else {//整单核销 + $cartInfo = $cartInfoServices->getCartColunm(['oid' => $orderInfo['id']], '*', 'cart_id'); + } + } + + $writeOffDataAll = []; + $writeOffData = ['uid' => $orderInfo['uid'], 'oid' => $oid, 'writeoff_code' => $orderInfo['verify_code'], 'add_time' => time()]; + foreach ($cartInfo as $cart) { + $write = $cartIds[$cart['cart_id']] ?? []; + $info = is_string($cart['cart_info']) ? json_decode($cart['cart_info'], true) : $cart['cart_info']; + if (!$cartIds || $write) { + $writeOffData['order_cart_id'] = $cart['id']; + $writeOffData['writeoff_num'] = $write['cart_num'] ?? $cart['cart_num']; + $writeOffData['type'] = $cart['type']; + $writeOffData['relation_id'] = $cart['relation_id']; + $writeOffData['product_id'] = $cart['product_id']; + $writeOffData['product_type'] = $cart['product_type']; + $writeOffData['writeoff_price'] = (float)bcmul((string)$info['truePrice'], (string)$writeOffData['writeoff_num'], 2); + $writeOffData['staff_id'] = $data['staff_id'] ?? 0; + $writeOffDataAll[] = $writeOffData; + } + } + if ($writeOffDataAll) { + $this->dao->saveAll($writeOffDataAll); + } + return true; + } + + /**核销记录 + * @param array $where + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function userOrderWriteOffRecords(array $where = []) + { + [$page, $limit] = $this->getPageValue(); + $list = $this->dao->getList($where, '*', $page, $limit, ['cartInfo']); + $count = $this->dao->count($where); + $times = []; + if ($list) { + foreach ($list as &$item) { + $item['time_key'] = $item['time'] = $item['add_time'] ? date('Y-m-d H:i', (int)$item['add_time']) : ''; + $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i', (int)$item['add_time']) : ''; + $value = is_string($item['cartInfo']['cart_info']) ? json_decode($item['cartInfo']['cart_info'], true) : $item['cartInfo']['cart_info']; + $value['productInfo']['store_name'] = $value['productInfo']['store_name'] ?? ""; + $value['productInfo']['store_name'] = substrUTf8($value['productInfo']['store_name'], 10, 'UTF-8', ''); + $item['cartInfo'] = $value; + } + $times = array_merge(array_unique(array_column($list, 'time_key'))); + } + + return ['count' => $count, 'list' => $list, 'time' => $times]; + } + +} diff --git a/app/services/order/supplier/SupplierOrderServices.php b/app/services/order/supplier/SupplierOrderServices.php new file mode 100644 index 0000000..11d895f --- /dev/null +++ b/app/services/order/supplier/SupplierOrderServices.php @@ -0,0 +1,325 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\order\supplier; + +use app\services\message\notice\NoticeSmsService; +use app\services\order\StoreOrderRefundServices; +use think\facade\Log; +// use app\webscoket\SocketPush; +use app\services\BaseServices; +use crmeb\traits\ServicesTrait; +use app\dao\order\StoreOrderDao; +use crmeb\services\CacheService; +use think\exception\ValidateException; +use app\services\order\StoreOrderCartInfoServices; + +/** + * 供应商订单 + * Class SupplierOrderServices + * @package app\sservices\order\supplier + * @mixin StoreOrderDao + */ +class SupplierOrderServices extends BaseServices +{ + + use ServicesTrait; + + /** + * 支付类型 + * @var string[] + */ + public $pay_type = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'alipay' => '支付宝支付', 'cash' => '现金支付', 'automatic' => '自动转账', 'store' => '微信支付']; + + /** + * SupplierOrderServices constructor. + * @param StoreOrderDao $dao + */ + public function __construct(StoreOrderDao $dao) + { + $this->dao = $dao; + } + + /** + * 配货单信息 + * @param array $id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getDistribution(array $id): array + { + $orderList = $this->dao->getList(['id' => $id], ['id', 'order_id', 'store_id', 'supplier_id', 'trade_no', 'real_name', 'user_phone', 'user_address', 'pay_time', 'pay_type', 'pay_postage as freight_price', 'coupon_price', 'deduction_price', 'use_integral', 'pay_price', 'mark']); + if (!$orderList) { + throw new ValidateException('订单不存在'); + } + /** @var StoreOrderCartInfoServices $services */ + $cartServices = app()->make(StoreOrderCartInfoServices::class); + foreach ($orderList as &$order) { + $order['pay_type_name'] = $this->pay_type[$order['pay_type']] ?? '其他方式'; + $order['pay_time'] = $order['pay_time'] ? date('Y-m-d H:i:s', (int)$order['pay_time']) : ''; + + $cartInfos = $cartServices->getCartColunm(['oid' => $order['id']], 'cart_num,is_writeoff,surplus_num,cart_info,refund_num,product_type,is_support_refund,is_gift,promotions_id', 'unique'); + + $i = 1; + $list = []; + + //核算优惠金额 + $vipTruePrice = 0; + foreach ($cartInfos as $cartInfo) { + $cart = json_decode($cartInfo['cart_info'], true); + $vipTruePrice = bcadd((string)$vipTruePrice, bcmul($cart['vip_truePrice'], $cart['cart_num'] ?: 1, 2), 2); + + $list[] = [ + 'index' => $i++, + 'store_name' => $cart['productInfo']['store_name'], + 'suk' => $cart['productInfo']['attrInfo']['suk'], + 'bar_code' => $cart['productInfo']['attrInfo']['bar_code'], + 'code' => $cart['productInfo']['attrInfo']['code'], + 'truePrice' => sprintf("%.2f", $cart['sum_price']), + 'cart_num' => $cart['cart_num'], + 'subtotal' => bcmul((string)$cart['sum_price'], (string)$cart['cart_num'], 2) + ]; + } + $order['user_address'] = str_replace(' ', '', $order['user_address']); + $order['vip_true_price'] = $vipTruePrice; + $order['list'] = $list; + } + + return $orderList; + } + + /** + * 供应商首页头部统计 + * @param int $supplierId + * @param array $time + * @return array + */ + public function homeStatics(int $supplierId, array $time): array + { + $data = []; + $where = ['time' => $time, 'supplier_id' => $supplierId]; + if ($supplierId < 1) { + $where['supplier_id'] = -1; + } + $orderWhere = ['paid' => 1, 'is_system_del' => 0, 'refund_status' => 0]; + $refundWhere = ['refund_type' => 6]; + + // 订单金额 + $data['pay_price'] = $this->dao->sum($where + $orderWhere, 'pay_price', true); + // 订单量 + $data['pay_count'] = $this->dao->count($where + $orderWhere); + /** @var StoreOrderRefundServices $orderRefundServices */ + $orderRefundServices = app()->make(StoreOrderRefundServices::class); + // 退款金额 + $data['refund_price'] = $orderRefundServices->sum($where + $refundWhere, 'refund_price', true); + // 退款订单数 + $data['refund_count'] = $orderRefundServices->count($where + $refundWhere); + return $data; + } + + /** + * 订单图表 + * @param int $supplierId + * @param array $time + * @return array + */ + public function orderCharts(int $supplierId, array $time): array + { + if (is_int($time[0]) && is_int($time[1])) { + $dayCount = (strtotime(date('Y/m/d', $time[1])) - strtotime(date('Y/m/d', $time[0]))) / 86400 + 1; + } else { + $time[0] = strtotime($time[0]); + $time[1] = strtotime($time[1]); + $dayCount = ($time[1] - $time[0]) / 86400 + 1; + } + if ($dayCount == 1) { + $num = 0; + } elseif ($dayCount > 1 && $dayCount <= 31) { + $num = 1; + } elseif ($dayCount > 31 && $dayCount <= 92) { + $num = 3; + } elseif ($dayCount > 92) { + $num = 30; + } + + if ($supplierId) { + $where = ['supplier_id' => $supplierId]; + } else { + $where = [['supplier_id', '>', 0]]; + } + + $data = $xAxis = $series = []; + if ($num == 0) { + $xAxis = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23']; + $timeType = '%H'; + } elseif ($num != 0) { + $dt_start = $time[0]; + $dt_end = $time[1]; + while ($dt_start <= $dt_end) { + if ($num == 30) { + $xAxis[] = date('Y-m', $dt_start); + $dt_start = strtotime("+1 month", $dt_start); + $timeType = '%Y-%m'; + } else { + $xAxis[] = date('m-d', $dt_start); + $dt_start = strtotime("+$num day", $dt_start); + $timeType = '%m-%d'; + } + } + } + $pay_price = array_column($this->dao->getOrderStatistics($where, $time, $timeType, 'add_time', 'sum(pay_price)', 'pay'), 'num', 'days'); + $pay_count = array_column($this->dao->getOrderStatistics($where, $time, $timeType, 'add_time', 'count(id)', 'pay'), 'num', 'days'); + $refund_price = array_column($this->dao->getOrderStatistics($where, $time, $timeType, 'add_time', 'sum(refund_price)', 'refund'), 'num', 'days'); + $refund_count = array_column($this->dao->getOrderStatistics($where, $time, $timeType, 'add_time', 'count(id)', 'refund'), 'num', 'days'); + + foreach ($xAxis as $item) { + $data['订单金额'][] = isset($pay_price[$item]) ? floatval($pay_price[$item]) : 0; + $data['订单量'][] = isset($pay_count[$item]) ? floatval($pay_count[$item]) : 0; + $data['退款金额'][] = isset($refund_price[$item]) ? floatval($refund_price[$item]) : 0; + $data['退款订单量'][] = isset($refund_count[$item]) ? floatval($refund_count[$item]) : 0; + } + foreach ($data as $key => $item) { + $series[] = [ + 'name' => $key, + 'data' => $item, + 'type' => 'line', + ]; + } + return compact('xAxis', 'series'); + } + + /** + * 订单来源 + * @param int $supplierId + * @param array string + * @return array + */ + public function getOrderChannel(int $supplierId, array $time): array + { + $bing_xdata = ['公众号', '小程序', 'H5', 'PC', 'APP']; + $color = ['#6DD230', '#FFAB2B', '#4BCAD5', '#1890FF', '#B37FEB']; + $bing_data = []; + if ($supplierId) { + $where = ['supplier_id' => $supplierId]; + } else { + $where = ['supplier_id' => -1]; + } + + foreach ($bing_xdata as $key => $item) { + $bing_data[] = [ + 'name' => $item, + 'value' => $this->dao->count(['paid' => 1, 'pid' => 0, 'is_channel' => $key, 'time' => $time] + $where), + 'itemStyle' => ['color' => $color[$key]] + ]; + } + + $list = []; + $count = array_sum(array_column($bing_data, 'value')); + foreach ($bing_data as $item) { + $list[] = [ + 'name' => $item['name'], + 'value' => $item['value'], + 'percent' => $count != 0 ? floatval(bcmul((string)bcdiv((string)$item['value'], (string)$count, 4), '100', 2)) : 0, + ]; + } + array_multisort(array_column($list, 'value'), SORT_DESC, $list); + return compact('bing_xdata', 'bing_data', 'list'); + } + + /** + * 订单类型 + * @param int $supplierId + * @param array string + * @return array + */ + public function getOrderType(int $supplierId, array $time): array + { + $bing_xdata = [0 => '普通订单', 1 => '秒杀订单', 2 => '砍价订单', 3 => '拼团订单', 4 => '', 5 => '套餐订单', 6 => '', 7 => '新人专享']; + $order_type = [0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '', 5 => '4', 6 => '6' , 7 => '9']; + $color = ['#64a1f4', '#3edeb5', '#70869f', '#ffc653', '', '#fc7d6a', '#fc7d2a', '']; + $bing_data = []; + + if ($supplierId) { + $where = ['supplier_id' => $supplierId]; + } else { + $where = ['supplier_id' => -1]; + } + foreach ($bing_xdata as $key => $item) { + if (empty($item)) continue; + $bing_data[] = [ + 'name' => $item, + 'value' => $this->dao->together(['paid' => 1, 'pid' => 0, 'type' => $order_type[$key] ?? 0, 'time' => $time] + $where, 'pay_price', 'sum'), + 'itemStyle' => ['color' => $color[$key]] + ]; + } + + $list = []; + $count = array_sum(array_column($bing_data, 'value')); + foreach ($bing_data as $item) { + $list[] = [ + 'name' => $item['name'], + 'value' => $item['value'], + 'percent' => $count != 0 ? floatval(bcmul((string)bcdiv((string)$item['value'], (string)$count, 4), '100', 2)) : 0, + ]; + } + unset($bing_xdata[4]); + $bing_xdata = array_values($bing_xdata); + array_multisort(array_column($list, 'value'), SORT_DESC, $list); + return compact('bing_xdata', 'bing_data', 'list'); + } + + /** + * 提醒发货 + * @param int $supplierId + * @param int $id + * @return bool + * @throws \Psr\SimpleCache\InvalidArgumentException + */ + public function deliverRemind(int $supplierId, int $id) + { + $expire = 600; + $val = time() + $expire; + + $order = $this->dao->get($id); + if (!$order) { + throw new ValidateException('订单不存在'); + } + $order = $order->toArray(); + + $cacheName = 'order_deliver_remind_' . $id; + if (CacheService::has($cacheName)) { + $interval = CacheService::get($cacheName); + $remain = $interval - time(); + if ($remain > 0) { + throw new ValidateException('请' . ceil($remain / 60) . '分钟后再次提醒'); + } + CacheService::delete($cacheName); + } else { + CacheService::set($cacheName, $val, $expire); + } + + //向供应商后台发送待发货订单消息 + try { + /** @var NoticeSmsService $NoticeSms */ + $NoticeSms = app()->make(NoticeSmsService::class); + $mark = 'admin_pay_success_code'; + $NoticeSms->setEvent($mark)->sendAdminPaySuccess($order); + + // SocketPush::instance()->setUserType('supplier')->to($supplierId)->type('WAIT_DELIVER_ORDER')->data(['order_id' => $order['order_id']])->push(); + + } catch (\Throwable $e) { + Log::error('向供应商发送提醒发货消息失败,失败原因:' . $e->getMessage()); + } + return true; + } +} \ No newline at end of file diff --git a/app/services/pay/OrderOfflineServices.php b/app/services/pay/OrderOfflineServices.php new file mode 100644 index 0000000..248024c --- /dev/null +++ b/app/services/pay/OrderOfflineServices.php @@ -0,0 +1,50 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\pay; + + +use app\services\BaseServices; +use app\services\order\StoreOrderServices; +use app\services\order\StoreOrderSuccessServices; +use think\exception\ValidateException; + +/** + * 线下支付 + * Class OrderOfflineServices + * @package app\services\pay + */ +class OrderOfflineServices extends BaseServices +{ + + /** + * 线下支付 + * @param int $id + * @return mixed + */ + public function orderOffline(int $id) + { + /** @var StoreOrderServices $orderSerives */ + $orderSerives = app()->make(StoreOrderServices::class); + $orderInfo = $orderSerives->get($id); + if (!$orderInfo) { + throw new ValidateException('订单不存在'); + } + + if ($orderInfo->paid) { + throw new ValidateException('订单已支付'); + } + /** @var StoreOrderSuccessServices $storeOrderSuccessServices */ + $storeOrderSuccessServices = app()->make(StoreOrderSuccessServices::class); + $storeOrderSuccessServices->paySuccess($orderInfo->toArray(), PayServices::OFFLINE_PAY); + return true; + } +} diff --git a/app/services/product/label/StoreProductLabelCateServices.php b/app/services/product/label/StoreProductLabelCateServices.php new file mode 100644 index 0000000..1625262 --- /dev/null +++ b/app/services/product/label/StoreProductLabelCateServices.php @@ -0,0 +1,112 @@ + +// +---------------------------------------------------------------------- +namespace app\services\product\label; + +use app\dao\other\CategoryDao; +use app\services\BaseServices; +use crmeb\services\FormBuilder as Form; +use think\facade\Route as Url; + +/** + * 商品标签分类 + * Class StoreProductLabelCateServices + * @package app\services\product\brand + * @mixin CategoryDao + */ +class StoreProductLabelCateServices extends BaseServices +{ + + /** + * 在分类库中2 + */ + const GROUP = 2; + + /** + * UserLabelCateServices constructor. + * @param CategoryDao $dao + */ + public function __construct(CategoryDao $dao) + { + $this->dao = $dao; + } + + /** + * 获取标签组列表(带标签) + * @param array $where + * @return array + */ + public function getProductLabelCateList(array $where) + { + [$page, $limit] = $this->getPageValue(); + $count = $this->dao->count($where); + $list = $this->dao->getCateList($where, $page, $limit, ['*'], ['productLabel']); + if ($list) { + foreach ($list as &$item) { + $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : ''; + } + } + return compact('list', 'count'); + } + + /** + * 获取所有的商品标签分类 + * @param int $type + * @param int $relation_id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getAllProductLabelCate(int $type = 0, int $relation_id = 0) + { + $where = [ + 'type' => $type, + 'relation_id' => $relation_id, + 'group' => self::GROUP + ]; + return $this->dao->getAll($where); + } + + /** + * 创建新增表单 + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function createForm() + { + return create_form('添加标签组', $this->form(), Url::buildUrl('/product/label_cate'), 'POST'); + } + + /** + * 创建编辑表单 + * @param $id + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function editForm(int $id) + { + $info = $this->dao->get($id); + return create_form('编辑标签组', $this->form($info), $this->url('/product/label_cate/' . $id), 'PUT'); + } + + /** + * 生成表单参数 + * @param array $info + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function form($info = []) + { + $f[] = Form::input('name', '标签组名称', $info['name'] ?? '')->maxlength(30)->required(); + $f[] = Form::number('sort', '排序', (int)($info['sort'] ?? 0))->min(0)->min(0); + return $f; + } +} diff --git a/app/services/product/product/StoreProductBatchProcessServices.php b/app/services/product/product/StoreProductBatchProcessServices.php new file mode 100644 index 0000000..b37f7ba --- /dev/null +++ b/app/services/product/product/StoreProductBatchProcessServices.php @@ -0,0 +1,268 @@ + +// +---------------------------------------------------------------------- +//declare (strict_types=1); +namespace app\services\product\product; + + +use app\jobs\product\ProductBatchJob; +use app\jobs\product\ProductCouponJob; +use app\jobs\product\ProductRelationJob; +use app\services\BaseServices; +use app\dao\product\product\StoreProductDao; +use app\services\product\category\StoreProductCategoryServices; +use crmeb\exceptions\AdminException; +use think\exception\ValidateException; + +/** + * 商品批量操作 + * Class StoreProductBatchProcessServices + * @package app\services\product\product + * @mixin StoreProductDao + */ +class StoreProductBatchProcessServices extends BaseServices +{ + /** + * 批量处理参数 + * @var array[] + */ + protected $data = [ + 'cate_id' => [],//分类ids + 'store_label_id' => [],//商品标签 + 'delivery_type' => [],//物流方式1:快递,2:门店自提,3:门店配送 + 'freight' => 1,//运费设置1:包邮,2:固定运费,3:运费模版 + 'postage' => 0,//邮费金额 + 'temp_id' => 0,//运费模版 + 'give_integral' => 0,//赠送积分 + 'coupon_ids' => [],//赠送优惠券ids + 'label_id' => [],//关联用户标签ids + 'recommend' => [],//活动推荐:is_hot、is_benefit、is_new、is_best、is_good +// 'custom_form' => [],//自定义留言 + 'system_form_id' => 0,//系统表单 + ]; + + /** + * StoreProductBatchProcessServices constructor. + * @param StoreProductDao $dao + */ + public function __construct(StoreProductDao $dao) + { + $this->dao = $dao; + } + + /** + * 根据搜索条件查询ids + * @param $where + * @return array + */ + public function getIdsByWhere($where) + { + $ids = []; + $cateIds = []; + if (isset($where['cate_id']) && $where['cate_id']) { + /** @var StoreProductCategoryServices $storeCategory */ + $storeCategory = app()->make(StoreProductCategoryServices::class); + $cateIds = $storeCategory->getColumn(['pid' => $where['cate_id']], 'id'); + } + if ($cateIds) { + $where['cate_id'] = array_unique(array_merge($where['cate_id'], $cateIds)); + } + /** @var StoreProductServices $productService */ + $productService = app()->make(StoreProductServices::class); + $dataInfo = $productService->getProductListByWhere($where, 'id'); + if ($dataInfo) { + $ids = array_unique(array_column($dataInfo, 'id')); + } + return $ids; + } + + /** + * 商品批量操作 + * @param int $type + * @param array $ids + * @param array $input_data + * @param bool $is_all + * @param array $where + * @return bool + */ + public function batchProcess(int $type, array $ids, array $input_data, bool $is_all = false, array $where = []) + { + //全选 + if ($is_all == 1) { + $ids = $this->getIdsByWhere($where); + } + $data = []; + $isBatch = true; + switch ($type) { + case 1://分类 + $isBatch = false; + $cate_id = $input_data['cate_id'] ?? 0; + if (!$cate_id) throw new ValidateException('请选择分类'); + + $data['cate_id'] = $cate_id; + break; + case 2://商品标签 不选默认清空标签 + $store_label_id = $input_data['store_label_id'] ?? []; + $data['store_label_id'] = $store_label_id; + break; + case 3://物流设置 + $data['delivery_type'] = $input_data['delivery_type'] ?? []; + if (!$data['delivery_type']) throw new AdminException('请选择商品配送方式'); + break; + case 4://购买即送积分、优惠券 + $isBatch = false; + $data['give_integral'] = $input_data['give_integral'] ?? 0; + $data['coupon_ids'] = $input_data['coupon_ids'] ?? []; + if (!$data['give_integral'] && !$data['coupon_ids']) { + throw new AdminException('请输入赠送积分或选择赠送优惠券'); + } + break; + case 5://关联用户标签 不选默认清空标签 + $label_id = $input_data['label_id'] ?? []; + $data['label_id'] = $label_id; + break; + case 6://活动推荐 + $recommend = $input_data['recommend'] ?? []; + $data['is_hot'] = $data['is_benefit'] = $data['is_new'] = $data['is_good'] = $data['is_best'] = 0; + if ($recommend) { + $arr = ['is_hot' , 'is_benefit', 'is_new', 'is_good', 'is_best']; + foreach ($recommend as $item) { + if (in_array($item, $arr)) { + $data[$item] = 1; + } + } + } + break; + case 7://自定义留言 可以为空 清空之前的设置 + $data['system_form_id'] = $input_data['system_form_id'] ?? 0; + break; + case 8://运费设置 + $data['freight'] = $input_data['freight'] ?? 0; + $data['postage'] = $input_data['postage'] ?? 0; + $data['temp_id'] = $input_data['temp_id'] ?? 0; + if ($data['freight'] == 2 && !$data['postage']) { + throw new AdminException('请设置运费金额'); + } + if ($data['freight'] == 3 && !$data['temp_id']) { + throw new AdminException('请选择运费模版'); + } + if ($data['freight'] == 1) { + $data['temp_id'] = 0; + $data['postage'] = 0; + } elseif ($data['freight'] == 2) { + $data['temp_id'] = 0; + } elseif ($data['freight'] == 3) { + $data['postage'] = 0; + } + break; + case 9://商品展示 + $data['show_type'] = $input_data['show_type'] ?? 0; + if (!in_array($data['show_type'], [0, 1, 2])) { + throw new AdminException('请重新选择商品展示'); + } + break; + default: + throw new AdminException('暂不支持该类型批操作'); + } + //加入批量队列 + ProductBatchJob::dispatchDo('productBatch', [$type, $ids, $data, $isBatch]); + return true; + } + + /** + * 执行批量修改eb_store_product + * @param array $ids + * @param array $data + * @return bool + */ + public function runBatch(array $ids, array $data, int $type = 2) + { + if (!$ids || !$data) { + return false; + } + if (isset($data['delivery_type']) && $data['delivery_type']) { + $data['delivery_type'] = is_array($data['delivery_type']) ? implode(',', $data['delivery_type']) : $data['delivery_type']; + } + switch ($type) { + case 2://商品标签 + $this->dao->batchUpdate($ids, ['store_label_id' => implode(',', $data['store_label_id'])], 'id'); + foreach ($ids as $id) { + ProductRelationJob::dispatch([$id, $data['store_label_id'], 3]); + } + break; + case 5://用户标签 + $this->dao->batchUpdate($ids, ['label_id' => implode(',', $data['label_id'])], 'id'); + foreach ($ids as $id) { + ProductRelationJob::dispatch([$id, $data['label_id'], 4]); + } + break; + case 6://活动推荐 用商品标签关联 + $this->dao->batchUpdate($ids, $data, 'id'); + $arr = ['is_hot' => 1, 'is_benefit' => 2, 'is_best' => 3, 'is_new' => 4, 'is_good' => 5]; + $label_ids = []; + foreach ($data as $key => $value) { + $label_id = $arr[$key] ?? 0; + if (!$label_id || !$value) continue; + $label_ids[] = $label_id; + } + foreach ($ids as $id) { + ProductRelationJob::dispatch([$id, $label_ids, 3]); + } + break; + default:// + $this->dao->batchUpdate($ids, $data, 'id'); + break; + } + return true; + } + + /** + * 保存商品分类 + * @param int $id + * @param array $data + * @return bool + */ + public function setPrdouctCate(int $id, array $data) + { + if (!$id || !$data) { + return true; + } + $cate_id = $data['cate_id'] ?? 0; + if ($cate_id) { + $this->dao->update($id, ['cate_id' => implode(',', $cate_id)]); + //商品分类关联 + ProductRelationJob::dispatch([$id, $cate_id, 1]); + } + return true; + } + + /** + * 保存商品赠送积分、优惠券 + * @param int $id + * @param array $data + * @return bool + */ + public function setGiveIntegralCoupon(int $id, array $data) + { + if (!$id || !$data) { + return true; + } + $give_integral = $data['give_integral'] ?? 0; + if ($give_integral) { + $this->dao->update($id, ['give_integral' => $give_integral]); + } + $coupon_ids = $data['coupon_ids'] ?? []; + if ($coupon_ids) { + //商品关联优惠券 + ProductCouponJob::dispatchDo('setProductCoupon', [$id, $coupon_ids]); + } + return true; + } +} diff --git a/app/services/product/product/StoreProductCouponServices.php b/app/services/product/product/StoreProductCouponServices.php new file mode 100644 index 0000000..097f856 --- /dev/null +++ b/app/services/product/product/StoreProductCouponServices.php @@ -0,0 +1,135 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\services\product\product; + +use app\services\BaseServices; +use app\dao\product\product\StoreProductCouponDao; +use app\services\activity\coupon\StoreCouponIssueServices; +use app\services\order\StoreOrderCartInfoServices; +use app\services\order\StoreOrderServices; +use app\services\user\UserServices; +use crmeb\exceptions\AdminException; +use crmeb\services\CacheService; +use think\exception\ValidateException; + +/** + * + * Class StoreProductCouponServices + * @package app\services\coupon + * @mixin StoreProductCouponDao + */ +class StoreProductCouponServices extends BaseServices +{ + + /** + * StoreProductCouponServices constructor. + * @param StoreProductCouponDao $dao + */ + public function __construct(StoreProductCouponDao $dao) + { + $this->dao = $dao; + } + + /** + * 商品关联优惠券 + * @param int $id + * @param array $coupon_ids + * @return bool + */ + public function setCoupon(int $id, array $coupon_ids) + { + $this->dao->delete(['product_id' => $id]); + if ($coupon_ids) { + $data = $data_all = []; + $data['product_id'] = $id; + $data['add_time'] = time(); + foreach ($coupon_ids as $cid) { + if (!empty($cid) && (int)$cid) { + $data['issue_coupon_id'] = $cid; + $data_all[] = $data; + } + } + $res = true; + if ($data_all) { + $res = $this->dao->saveAll($data_all); + } + if (!$res) throw new AdminException('关联优惠券失败!'); + } + return true; + } + + /** + * 获取下单赠送优惠券 + * @param int $uid + * @param $orderId + * @return mixed + * @throws \Psr\SimpleCache\InvalidArgumentException + */ + public function getOrderProductCoupon(int $uid, $orderId) + { + /** @var StoreOrderServices $storeOrder */ + $storeOrder = app()->make(StoreOrderServices::class); + $order = $storeOrder->getOne(['order_id' => $orderId]); + if (!$order || $order['uid'] != $uid) { + throw new ValidateException('订单不存在'); + } + $key = 'order_product_coupon_' . $uid . '_' . $order['id']; + return CacheService::redisHandler()->get($key, []); + } + + /** + * 下单赠送优惠劵 + * @param int $uid + * @param $orderId + * @return array + */ + public function giveOrderProductCoupon(int $uid, $orderId) + { + /** @var UserServices $userServices */ + $userServices = app()->make(UserServices::class); + $user = $userServices->getUserInfo($uid); + if (!$user) { + throw new ValidateException('用户不存在'); + } + /** @var StoreOrderServices $storeOrder */ + $storeOrder = app()->make(StoreOrderServices::class); + $order = $storeOrder->getOne(['id' => $orderId]); + if (!$order || $order['uid'] != $uid) { + throw new ValidateException('订单不存在'); + } + /** @var StoreOrderCartInfoServices $storeOrderCartInfo */ + $storeOrderCartInfo = app()->make(StoreOrderCartInfoServices::class); + $productIds = $storeOrderCartInfo->getColumn(['oid' => $order['id']], 'product_id'); + $list = []; + if ($productIds) { + $couponList = $this->dao->getProductCoupon($productIds); + if ($couponList) { + /** @var StoreCouponIssueServices $storeCoupon */ + $storeCoupon = app()->make(StoreCouponIssueServices::class); + $list = $storeCoupon->orderPayGiveCoupon($uid, array_column($couponList, 'issue_coupon_id')); + if ($list) { + $ids = array_column($list, 'cid'); + $coupons = $storeCoupon->getColumn(['id' => $ids], 'id,coupon_type', 'id'); + foreach ($list as &$item) { + $item['coupon_type'] = $coupons[$item['cid']]['coupon_type'] ?? 1; + $item['add_time'] = date('Y-m-d', $item['add_time']); + $item['end_time'] = date('Y-m-d', $item['end_time']); + } + } + } + } + $key = 'order_product_coupon_' . $uid . '_' . $orderId; + CacheService::redisHandler()->set($key, $list, 7200); + return true; + } +} diff --git a/app/services/product/product/StoreProductUnitServices.php b/app/services/product/product/StoreProductUnitServices.php new file mode 100644 index 0000000..745d643 --- /dev/null +++ b/app/services/product/product/StoreProductUnitServices.php @@ -0,0 +1,116 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\product\product; + + +use app\dao\product\product\StoreProductUnitDao; +use app\services\BaseServices; +use crmeb\services\FormBuilder; +use think\exception\ValidateException; + + +/** + * 商品单位 + * Class StoreProductUnitServices + * @package app\services\product\product + * @mixin StoreProductUnitDao + */ +class StoreProductUnitServices extends BaseServices +{ + /** + * StoreProductUnitServices constructor. + * @param StoreProductUnitDao $dao + */ + public function __construct(StoreProductUnitDao $dao) + { + $this->dao = $dao; + } + + /** + * 获取所有商品单位列表 + * @param int $type + * @param int $relation_id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getAllUnitList(int $type = 0, int $relation_id = 0) + { + $where = []; +// $where['type'] = $type; +// $where['relation_id'] = $relation_id; + $where['status'] = 1; + $where['is_del'] = 0; + return $this->dao->getList($where, 'id,name'); + } + + /** + * 获取商品单位 + * @param array $where + * @param string $field + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getUnitList(array $where, string $field = '*') + { + [$page, $limit] = $this->getPageValue(); + $list = $this->dao->getList($where, $field, $page, $limit); + $count = $this->dao->count($where); + return compact('list', 'count'); + } + + + /** + * 创建表单 + * @param array $cataData + * @return array + */ + public function unitCateForm(array $cataData = []) + { + $f[] = FormBuilder::input('name', '单位名称', $cataData['name'] ?? '')->maxlength(15)->required(); + $f[] = FormBuilder::number('sort', '排序', (int)($cataData['sort'] ?? 0))->min(0); + return $f; + } + + /** + * 创建表单 + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function createForm() + { + return create_form('添加商品单位', $this->unitCateForm(), $this->url('/product/unit'), 'POST'); + } + + /** + * 修改分类标签表单 + * @param int $id + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function updateForm(int $id) + { + $unit = $this->dao->get($id); + if (!$unit) { + throw new ValidateException('分类标签没有查到'); + } + return create_form('编辑商品单位', $this->unitCateForm($unit->toArray()), $this->url('/product/unit/' . $id), 'PUT'); + } + + +} diff --git a/app/services/product/specs/StoreProductSpecsTemplateServices.php b/app/services/product/specs/StoreProductSpecsTemplateServices.php new file mode 100644 index 0000000..5174fe0 --- /dev/null +++ b/app/services/product/specs/StoreProductSpecsTemplateServices.php @@ -0,0 +1,84 @@ + +// +---------------------------------------------------------------------- +namespace app\services\product\specs; + +use app\dao\other\CategoryDao; +use app\services\BaseServices; + +/** + * 商品参数模版 + * Class StoreProductSpecsTemplateServices + * @package app\services\product\specs + * @mixin CategoryDao + */ +class StoreProductSpecsTemplateServices extends BaseServices +{ + + /** + * 在分类库中3 + */ + const GROUP = 3; + + /** + * UserLabelCateServices constructor. + * @param CategoryDao $dao + */ + public function __construct(CategoryDao $dao) + { + $this->dao = $dao; + } + + /** + * 获取所有参数模版 + * @param array $where + * @param int $type + * @param int $relation_id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getProductSpecsTemplateList(array $where, int $type = 0, int $relation_id = 0) + { + [$page, $limit] = $this->getPageValue(); + $where = array_merge($where, ['type' => $type, 'relation_id' => $relation_id, 'group' => 3]); + $count = $this->dao->count($where); + $list = $this->dao->getCateList($where, $page, $limit, ['*']); + if ($list) { + foreach ($list as &$item) { + $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : ''; + } + } + return compact('list', 'count'); + } + + /** + * 获取所有商品参数 + * @param int $type + * @param int $relation_id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getAllSpecs(int $type = 0, int $relation_id = 0) + { + $where = []; +// $where['relation_id'] = $relation_id; +// $where['type'] = $type; + $where['group'] = 3; + return $this->dao->getCateList($where, 0, 0, ['id', 'name'], ['specs' => function($query) { + $query->where('status', 1); + }]); + } + + +} diff --git a/app/services/system/config/SystemConfigTabServices.php b/app/services/system/config/SystemConfigTabServices.php new file mode 100644 index 0000000..c5a2cd9 --- /dev/null +++ b/app/services/system/config/SystemConfigTabServices.php @@ -0,0 +1,142 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\system\config; + + +use app\dao\system\config\SystemConfigTabDao; +use app\services\BaseServices; +use crmeb\exceptions\AdminException; +use crmeb\services\FormBuilder as Form; + +/** + * 系统配置分类 + * Class SystemConfigTabServices + * @package app\services\system\config + * @mixin SystemConfigTabDao + */ +class SystemConfigTabServices extends BaseServices +{ + /** + * SystemConfigTabServices constructor. + * @param SystemConfigTabDao $dao + */ + public function __construct(SystemConfigTabDao $dao) + { + $this->dao = $dao; + } + + /** + * 系统设置头部分类读取 + * @param int $pid + * @param int $is_store + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getConfigTab(int $pid, int $is_store = 0) + { + $list = $this->dao->getConfigTabAll(['status' => 1, 'pid' => $pid, 'is_store' => $is_store], ['id', 'id as value', 'title as label', 'pid', 'icon', 'type'], $pid ? [] : [['type', '=', '0']]); + return get_tree_children($list); + } + + /** + * 获取配置分类列表 + * @param array $where + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getConfgTabList(array $where) + { + [$page, $limit] = $this->getPageValue(); + $list = $this->dao->getConfgTabList($where, $page, $limit); + $count = $this->dao->count($where); + $menusValue = []; + foreach ($list as $item) { + $menusValue[] = $item->getData(); + } + $list = get_tree_children($menusValue); + return compact('list', 'count'); + } + + /** + * 获取配置分类选择下拉树 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getSelectForm() + { + $menuList = $this->dao->getConfigTabAll([], ['id as value', 'pid', 'title as label']); + $menus = [['value' => 0, 'label' => '顶级按钮']]; + $list = get_tree_children($menuList, 'children', 'value'); + $menus = array_merge($menus, $list); +// foreach ($list as $menu) { +// $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']]; +// } + return $menus; + } + + /** + * 创建form表单 + * @param array $formData + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function createConfigTabForm(array $formData = []) + { + $pid[] = isset($formData['pid']) ? $formData['pid'] : 0; + $form[] = Form::radio('is_store', '类型', $formData['is_store'] ?? 0)->options([['value' => 0, 'label' => '总后台'], ['value' => 1, 'label' => '门店后台']]); + $form[] = Form::cascader('pid', '父级分类', $pid)->data($this->getSelectForm())->changeOnSelect(true); + $form[] = Form::input('title', '分类名称', $formData['title'] ?? ''); + $form[] = Form::input('eng_title', '分类字段英文', $formData['eng_title'] ?? ''); + $form[] = Form::frameInput('icon', '图标', $this->url(config('admin.admin_prefix') . '/widget.widgets/icon', ['fodder' => 'icon'], true), $formData['icon'] ?? '')->icon('ios-ionic')->height('435px'); + $form[] = Form::radio('type', '类型', $formData['type'] ?? 0)->options([ + ['value' => 0, 'label' => '系统'], + ['value' => 3, 'label' => '其它'] + ]); + $form[] = Form::radio('status', '状态', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]); + $form[] = Form::number('sort', '排序', (int)($formData['sort'] ?? 0))->min(0); + return $form; + } + + /** + * 添加配置分类表单 + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function createForm() + { + return create_form('添加配置分类', $this->createConfigTabForm(), $this->url('/setting/config_class')); + } + + /** + * 修改配置分类表单 + * @param int $id + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function updateForm(int $id) + { + $configTabInfo = $this->dao->get($id); + if (!$configTabInfo) { + throw new AdminException('没有查到数据,无法修改!'); + } + return create_form('编辑配置分类', $this->createConfigTabForm($configTabInfo->toArray()), $this->url('/setting/config_class/' . $id), 'PUT'); + } +} diff --git a/app/services/user/label/UserLabelCateServices.php b/app/services/user/label/UserLabelCateServices.php new file mode 100644 index 0000000..b1a38eb --- /dev/null +++ b/app/services/user/label/UserLabelCateServices.php @@ -0,0 +1,184 @@ + +// +---------------------------------------------------------------------- + +namespace app\services\user\label; + + +use app\dao\other\CategoryDao; +use app\services\BaseServices; +use crmeb\services\CacheService; +use crmeb\services\FormBuilder; +use crmeb\traits\ServicesTrait; +use think\exception\ValidateException; + +/** + * 用户标签分类 + * Class UserLabelCateServices + * @package app\services\user\label + * @mixin CategoryDao + */ +class UserLabelCateServices extends BaseServices +{ + /** + * 在分类库中0 + */ + const GROUP = 0; + + use ServicesTrait; + + /** + * 标签分类缓存 + * @var string + */ + protected $cacheName = 'label_list_all'; + + /** + * UserLabelCateServices constructor. + * @param CategoryDao $dao + */ + public function __construct(CategoryDao $dao) + { + $this->dao = $dao; + } + + /** + * 获取标签分类 + * @param array $where + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getLabelList(array $where) + { + [$page, $limit] = $this->getPageValue(); + $list = $this->dao->getCateList($where, $page, $limit); + $count = $this->dao->count($where); + return compact('list', 'count'); + } + + /** + * 获取tree数据 + * @param array $where + * @param array|string[] $field + * @param array $with + * @return array + */ + public function getLabelTree(array $where, array $field = ['*'], array $with = []) + { + return $this->dao->getCateList($where, 0, 0, $field, $with); + } + + /** + * 删除分类缓存 + * @param int $type + * @param int $relation_id + * @return bool + * @throws \Psr\SimpleCache\InvalidArgumentException + */ + public function deleteCateCache(int $type = 0, int $relation_id = 0) + { + $key = $this->cacheName . '_' . $type . '_' . $relation_id; + return CacheService::delete($key); + } + + /** + * 获取标签全部分类 + * @param int $type + * @param int $relation_id + * @return bool|mixed|null + */ + public function getLabelCateAll(int $type = 0, int $relation_id = 0) + { + $key = $this->cacheName . '_' . $type . '_' . $relation_id; + return CacheService::get($key, function () use ($type, $relation_id) { + return $this->dao->getCateList(['type' => $type, 'owner_id' => 0, 'relation_id' => $relation_id, 'group' => 0]); + }); + } + + /** + * 标签分类表单 + * @param array $cataData + * @return mixed + */ + public function labelCateForm(array $cataData = []) + { + $f[] = FormBuilder::input('name', '分类名称', $cataData['name'] ?? '')->maxlength(20)->required(); + $f[] = FormBuilder::number('sort', '排序', (int)($cataData['sort'] ?? 0))->min(0); + return $f; + } + + /** + * 创建表单 + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function createForm() + { + return create_form('添加标签分类', $this->labelCateForm(), $this->url('/user/user_label_cate'), 'POST'); + } + + /** + * 修改分类标签表单 + * @param int $id + * @return array + * @throws \FormBuilder\Exception\FormBuilderException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function updateForm(int $id) + { + $labelCate = $this->dao->get($id); + if (!$labelCate) { + throw new ValidateException('分类标签没有查到'); + } + return create_form('编辑标签分类', $this->labelCateForm($labelCate->toArray()), $this->url('user/user_label_cate/' . $id), 'PUT'); + } + + /** + * 用户标签列表 + * @param int $uid + * @param int $type + * @param int $relation_id + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getUserLabel(int $uid = 0, int $type = 0, int $relation_id = 0) + { + $list = $this->dao->getAll(['group' => 0, 'type' => $type, 'relation_id' => $relation_id], ['label']); + $labelIds = []; + if ($uid) { + /** @var UserLabelRelationServices $services */ + $services = app()->make(UserLabelRelationServices::class); + $labelIds = $services->getUserLabels($uid, $type, $relation_id); + } + foreach ($list as $key => &$item) { + if (is_array($item['label'])) { + if (!$item['label']) { + unset($list[$key]); + continue; + } + foreach ($item['label'] as &$value) { + if (in_array($value['id'], $labelIds)) { + $value['disabled'] = true; + } else { + $value['disabled'] = false; + } + } + } + + } + return array_merge($list); + } +} diff --git a/app/validate/admin/order/StoreOrderValidate.php b/app/validate/admin/order/StoreOrderValidate.php new file mode 100644 index 0000000..b04b6d2 --- /dev/null +++ b/app/validate/admin/order/StoreOrderValidate.php @@ -0,0 +1,48 @@ + +// +---------------------------------------------------------------------- +namespace app\validate\admin\order; + +use think\Validate; + +/** + * + * Class StoreOrderValidate + * @package app\validates\admin + */ +class StoreOrderValidate extends Validate +{ + + protected $rule = [ + 'order_id' => ['require','length'=>'1,32','alphaNum'], + 'total_price' => ['require','float'], + 'total_postage' => ['require','float'], + 'pay_price' => ['require','float'], + 'pay_postage' => ['require','float'], + 'gain_integral' => ['float'], + ]; + + protected $message = [ + 'order_id.require' => '订单号必须存在', + 'order_id.length' => '订单号有误', + 'order_id.alphaNum' => '订单号必须为字母和数字', + 'total_price.require' => '订单金额必须填写', + 'total_price.float' => '订单金额必须为数字', + 'pay_price.require' => '订单金额必须填写', + 'pay_price.float' => '订单金额必须为数字', + 'pay_postage.require' => '订单邮费必须填写', + 'pay_postage.float' => '订单邮费必须为数字', + 'gain_integral.float' => '赠送积分必须为数字', + ]; + + protected $scene = [ + + ]; +} diff --git a/app/validate/api/user/RegisterValidates.php b/app/validate/api/user/RegisterValidates.php new file mode 100644 index 0000000..2cdcab7 --- /dev/null +++ b/app/validate/api/user/RegisterValidates.php @@ -0,0 +1,53 @@ + +// +---------------------------------------------------------------------- +namespace app\validate\api\user; + + +use think\Validate; + +/** + * 注册验证 + * Class RegisterValidates + * @package app\http\validates\api\user + */ +class RegisterValidates extends Validate +{ + protected $regex = ['phone' => '/^1[3456789]\d{9}$/']; + + protected $rule = [ + 'phone' => 'require|regex:phone', + 'account' => 'require|regex:phone', + 'captcha' => 'require|length:6', + 'password' => 'require', + ]; + + protected $message = [ + 'phone.require' => '手机号必须填写', + 'phone.regex' => '手机号格式错误', + 'account.require' => '手机号必须填写', + 'account.regex' => '手机号格式错误', + 'captcha.require' => '验证码必须填写', + 'captcha.length' => '验证码长度不正确', + 'password.require' => '密码必须填写', + ]; + + + public function sceneCode() + { + return $this->only(['phone']); + } + + + public function sceneRegister() + { + return $this->only(['account', 'captcha', 'password']); + } +} diff --git a/crmeb/traits/MacroTrait.php b/crmeb/traits/MacroTrait.php new file mode 100644 index 0000000..8742952 --- /dev/null +++ b/crmeb/traits/MacroTrait.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- + +namespace crmeb\traits; + +use app\Request; + +/** + * Trait MacroTrait + * @package crmeb\traits + * @property Request $request + */ +trait MacroTrait +{ + + /** + * 获取request内的值 + * @param string $name + * @param null $default + * @return |null + */ + public function getMacro(string $name, $default = null) + { + return $this->request->hasMacro($name) ? $this->request->{$name}() : $default; + } +} diff --git a/crmeb/utils/Captcha.php b/crmeb/utils/Captcha.php new file mode 100644 index 0000000..9189a36 --- /dev/null +++ b/crmeb/utils/Captcha.php @@ -0,0 +1,317 @@ + +// +---------------------------------------------------------------------- +namespace crmeb\utils; + + +use crmeb\services\CacheService; +use think\facade\Config; +use think\Response; + +/** + * Class Captcha + * @package crmeb\utils + */ +class Captcha +{ + // 验证码图片实例 + private $im = null; + // 验证码字体颜色 + private $color = null; + // 验证码字符集合 + protected $codeSet = '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY'; + // 验证码过期时间(s) + protected $expire = 1800; + // 使用中文验证码 + protected $useZh = false; + // 中文验证码字符串 + protected $zhSet = '们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借'; + // 使用背景图片 + protected $useImgBg = false; + // 验证码字体大小(px) + protected $fontSize = 25; + // 是否画混淆曲线 + protected $useCurve = false; + // 是否添加杂点 + protected $useNoise = true; + // 验证码图片高度 + protected $imageH = 0; + // 验证码图片宽度 + protected $imageW = 0; + // 验证码位数 + protected $length = 4; + // 验证码字体,不设置随机获取 + protected $fontttf = ''; + // 背景颜色 + protected $bg = [243, 251, 254]; + //算术验证码 + protected $math = false; + //验证码 + protected $generator; + + /** + * 架构方法 设置参数 + * Captcha constructor. + * @param array $config + */ + public function __construct(array $config = []) + { + $this->length = $config['length'] ?? Config::get('captcha.length', $this->length); + $this->imageW = $config['imageW'] ?? $this->imageW; + $this->imageH = $config['imageH'] ?? $this->imageH; + $this->useCurve = $config['useCurve'] ?? $this->useCurve; + $this->fontSize = $config['fontSize'] ?? $this->fontSize; + $this->useImgBg = $config['useImgBg'] ?? $this->useImgBg; + $this->useZh = $config['useZh'] ?? $this->useZh; + $this->expire = $config['expire'] ?? $this->expire; + $this->math = $config['math'] ?? $this->math; + $this->zhSet = $config['zhSet'] ?? $this->zhSet; + $this->codeSet = $config['codeSet'] ?? $this->codeSet; + } + + /** + * 创建验证码 + * @return array + * @throws Exception + */ + public function generate(): array + { + $bag = ''; + + if ($this->math) { + $this->useZh = false; + + $x = random_int(10, 30); + $y = random_int(1, 9); + $bag = "{$x} + {$y} = "; + $key = $x + $y; + $key .= ''; + } else { + if ($this->useZh) { + $characters = preg_split('/(?zhSet); + } else { + $characters = str_split($this->codeSet); + } + mt_srand(); + for ($i = 0; $i < $this->length; $i++) { + $bag .= $characters[rand(0, count($characters) - 1)]; + } + + $key = mb_strtolower($bag, 'UTF-8'); + } + + $hash = password_hash($key, PASSWORD_BCRYPT, ['cost' => 10]); + + $generator = [ + 'value' => $bag, + 'key' => $hash, + ]; + CacheService::set('captcha_' . $key, $generator, $this->expire); + return $generator; + } + + /** + * 验证验证码是否正确 + * @access public + * @param string $code 用户验证码 + * @return bool 用户验证码是否正确 + */ + public function check(string $code): bool + { + $code = mb_strtolower(trim($code), 'UTF-8'); + $name = 'captcha_' . $code; + if (!CacheService::has($name) || !($generator = CacheService::get($name))) { + return false; + } + $key = $generator['key'] ?? ''; + $res = password_verify($code, $key); + + if ($res) { + CacheService::delete($name); + } + + return $res; + } + + /** + * 输出验证码 + * @param array|null $generator + * @return $this + */ + public function create(array $generator = null): Response + { + if (!$generator) { + $generator = $this->generate(); + } + + // 图片宽(px) + $this->imageW || $this->imageW = $this->length * $this->fontSize * 1.5 + $this->length * $this->fontSize / 2; + // 图片高(px) + $this->imageH || $this->imageH = $this->fontSize * 2.5; + // 建立一幅 $this->imageW x $this->imageH 的图像 + $this->im = imagecreate($this->imageW, $this->imageH); + // 设置背景 + imagecolorallocate($this->im, $this->bg[0], $this->bg[1], $this->bg[2]); + mt_srand(); + // 验证码字体随机颜色 + $this->color = imagecolorallocate($this->im, mt_rand(1, 150), mt_rand(1, 150), mt_rand(1, 150)); + + // 验证码使用随机字体 + $ttfPath = dirname(dirname(app()->getThinkPath())) . DS . 'think-captcha' . DS . 'assets/' . ($this->useZh ? 'zhttfs' : 'ttfs') . '/'; + if (empty($this->fontttf)) { + $dir = dir($ttfPath); + $ttfs = []; + while (false !== ($file = $dir->read())) { + if ('.' != $file[0] && substr($file, -4) == '.ttf') { + $ttfs[] = $file; + } + } + $dir->close(); + mt_srand(); + $this->fontttf = $ttfs[array_rand($ttfs)]; + } + + + $fontttf = $ttfPath . $this->fontttf; + + if ($this->useImgBg) { + $this->background(); + } + + if ($this->useNoise) { + // 绘杂点 + $this->writeNoise(); + } + if ($this->useCurve) { + // 绘干扰线 + $this->writeCurve(); + } + // 绘验证码 + $text = $this->useZh ? preg_split('/(? $char) { + + $x = $this->fontSize * ($index + 1) * mt_rand(1.2, 1.6) * ($this->math ? 1 : 1.5); + $y = $this->fontSize + mt_rand(10, 20); + $angle = $this->math ? 0 : mt_rand(-40, 40); + + imagettftext($this->im, $this->fontSize, $angle, $x, $y, $this->color, $fontttf, $char); + } + + ob_start(); + // 输出图像 + imagepng($this->im); + $content = ob_get_clean(); + imagedestroy($this->im); + return response($content, 200)->contentType('image/png'); + } + + /** + * 画一条由两条连在一起构成的随机正弦函数曲线作干扰线(你可以改成更帅的曲线函数) + * + * 高中的数学公式咋都忘了涅,写出来 + * 正弦型函数解析式:y=Asin(ωx+φ)+b + * 各常数值对函数图像的影响: + * A:决定峰值(即纵向拉伸压缩的倍数) + * b:表示波形在Y轴的位置关系或纵向移动距离(上加下减) + * φ:决定波形与X轴位置关系或横向移动距离(左加右减) + * ω:决定周期(最小正周期T=2π/∣ω∣) + * + */ + protected function writeCurve(): void + { + $px = $py = 0; + mt_srand(); + // 曲线前部分 + $A = mt_rand(1, $this->imageH / 2); // 振幅 + $b = mt_rand(-$this->imageH / 4, $this->imageH / 4); // Y轴方向偏移量 + $f = mt_rand(-$this->imageH / 4, $this->imageH / 4); // X轴方向偏移量 + $T = mt_rand($this->imageH, $this->imageW * 2); // 周期 + $w = (2 * M_PI) / $T; + + $px1 = 0; // 曲线横坐标起始位置 + $px2 = mt_rand($this->imageW / 2, $this->imageW * 0.8); // 曲线横坐标结束位置 + + for ($px = $px1; $px <= $px2; $px = $px + 1) { + if (0 != $w) { + $py = $A * sin($w * $px + $f) + $b + $this->imageH / 2; // y = Asin(ωx+φ) + b + $i = (int)($this->fontSize / 5); + while ($i > 0) { + imagesetpixel($this->im, $px + $i, $py + $i, $this->color); // 这里(while)循环画像素点比imagettftext和imagestring用字体大小一次画出(不用这while循环)性能要好很多 + $i--; + } + } + } + + // 曲线后部分 + $A = mt_rand(1, $this->imageH / 2); // 振幅 + $f = mt_rand(-$this->imageH / 4, $this->imageH / 4); // X轴方向偏移量 + $T = mt_rand($this->imageH, $this->imageW * 2); // 周期 + $w = (2 * M_PI) / $T; + $b = $py - $A * sin($w * $px + $f) - $this->imageH / 2; + $px1 = $px2; + $px2 = $this->imageW; + + for ($px = $px1; $px <= $px2; $px = $px + 1) { + if (0 != $w) { + $py = $A * sin($w * $px + $f) + $b + $this->imageH / 2; // y = Asin(ωx+φ) + b + $i = (int)($this->fontSize / 5); + while ($i > 0) { + imagesetpixel($this->im, $px + $i, $py + $i, $this->color); + $i--; + } + } + } + } + + /** + * 画杂点 + * 往图片上写不同颜色的字母或数字 + */ + protected function writeNoise(): void + { + mt_srand(); + $codeSet = '2345678abcdefhijkmnpqrstuvwxyz'; + for ($i = 0; $i < 10; $i++) { + //杂点颜色 + $noiseColor = imagecolorallocate($this->im, mt_rand(150, 225), mt_rand(150, 225), mt_rand(150, 225)); + for ($j = 0; $j < 5; $j++) { + // 绘杂点 + imagestring($this->im, 5, mt_rand(-10, $this->imageW), mt_rand(-10, $this->imageH), $codeSet[mt_rand(0, 29)], $noiseColor); + } + } + } + + /** + * 绘制背景图片 + * 注:如果验证码输出图片比较大,将占用比较多的系统资源 + */ + protected function background(): void + { + $path = dirname(dirname(app()->getThinkPath())) . DS . 'think-captcha' . DS . '/assets/bgs/'; + $dir = dir($path); + + $bgs = []; + while (false !== ($file = $dir->read())) { + if ('.' != $file[0] && substr($file, -4) == '.jpg') { + $bgs[] = $path . $file; + } + } + $dir->close(); + mt_srand(); + $gb = $bgs[array_rand($bgs)]; + + [$width, $height] = @getimagesize($gb); + // Resample + $bgImage = @imagecreatefromjpeg($gb); + @imagecopyresampled($this->im, $bgImage, 0, 0, 0, 0, $this->imageW, $this->imageH, $width, $height); + @imagedestroy($bgImage); + } +} diff --git a/route/supplier.php b/route/supplier.php index a4ca305..fa02e8c 100644 --- a/route/supplier.php +++ b/route/supplier.php @@ -5,6 +5,8 @@ use app\common\middleware\AllowOriginMiddleware; use app\common\middleware\InstallMiddleware; use app\common\middleware\AuthTokenMiddleware; use app\common\middleware\StationOpenMiddleware; +use app\common\middleware\SupplierCheckRoleMiddleware; +use app\common\middleware\SupplierLogMiddleware; use think\facade\Config; use think\facade\Route; use think\Response; @@ -12,7 +14,7 @@ use think\Response; /** * 供应商路由配置 */ -Route::group('supplierapi', function () { +Route::group('supplierapi/', function () { /** * 不需要登录不验证权限 @@ -98,8 +100,8 @@ Route::group('supplierapi', function () { })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); @@ -129,8 +131,8 @@ Route::group('supplierapi', function () { Route::get('supplier_flowing_water/fund_record_info', 'finance.SupplierFlowingWater/fundRecordInfo')->option(['real_name' => '供应商账单详情']); })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); @@ -151,8 +153,8 @@ Route::group('supplierapi', function () { })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** @@ -254,8 +256,8 @@ Route::group('supplierapi', function () { })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** @@ -401,8 +403,8 @@ Route::group('supplierapi', function () { })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** @@ -419,8 +421,8 @@ Route::group('supplierapi', function () { Route::get('financeRecord', 'export.ExportExcel/financeRecord')->option(['real_name' => '供应商账单导出']); })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** @@ -437,8 +439,8 @@ Route::group('supplierapi', function () { Route::get('spread_list/:id', 'user.User/spreadList')->name('spreadList')->option(['real_name' => '推荐人记录列表']); })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** @@ -457,8 +459,8 @@ Route::group('supplierapi', function () { Route::get('stop/wrong_queue/:id', 'queue.Queue/stop_wrong_queue')->option(['real_name' => '停止队列任务']); })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** @@ -479,22 +481,27 @@ Route::group('supplierapi', function () { Route::get('detail/:id', 'Refund/detail')->option(['real_name' => '售后订单详情']); })->middleware([ AuthTokenMiddleware::class, - \app\http\middleware\supplier\SupplierCheckRoleMiddleware::class, - \app\http\middleware\supplier\SupplierLogMiddleware::class + SupplierCheckRoleMiddleware::class, + SupplierLogMiddleware::class ]); /** * miss 路由 */ + // Route::miss(function () { + // if (app()->request->isOptions()) { + // $header = Config::get('cookie.header'); + // $header['Access-Control-Allow-Origin'] = app()->request->header('origin'); + // return Response::create('ok')->code(200)->header($header); + // } else + // return Response::create()->code(404); + // }); Route::miss(function () { - if (app()->request->isOptions()) { - $header = Config::get('cookie.header'); - $header['Access-Control-Allow-Origin'] = app()->request->header('origin'); - return Response::create('ok')->code(200)->header($header); - } else - return Response::create()->code(404); - }); - -})->prefix('supplier.')->middleware(InstallMiddleware::class)->middleware(AllowOriginMiddleware::class)->middleware(StationOpenMiddleware::class); + return app('json')->fail('接口不存在'); + })->middleware(AllowOriginMiddleware::class); +})->prefix('supplier.') + ->middleware(InstallMiddleware::class) + ->middleware(AllowOriginMiddleware::class) + ->middleware(StationOpenMiddleware::class);