From d03036b43e8a831744b0f9f6ebabd289dd09dd49 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Sat, 18 Nov 2023 18:00:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=95=86=E6=88=B7?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=AF=E5=88=86=E5=95=86=E5=93=81=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=AE=A1=E7=90=86=20=E4=BF=AE=E6=94=B9=EF=BC=9A?= =?UTF-8?q?=E6=80=BB=E5=B9=B3=E5=8F=B0=E7=A7=AF=E5=88=86=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=86=85=E5=AE=B9=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreOrderDao.php | 3 + .../order/PointsOrderCreateRepository.php | 40 ++-- .../store/pionts/PointsProductRepository.php | 1 + app/controller/merchant/points/Category.php | 100 ++++++++++ app/controller/merchant/points/Order.php | 187 ++++++++++++++++++ app/controller/merchant/points/Product.php | 187 ++++++++++++++++++ .../merchant/StoreCategoryValidate.php | 22 +++ route/merchant/points.php | 122 ++++++++++++ 8 files changed, 646 insertions(+), 16 deletions(-) create mode 100644 app/controller/merchant/points/Category.php create mode 100644 app/controller/merchant/points/Order.php create mode 100644 app/controller/merchant/points/Product.php create mode 100644 app/validate/merchant/StoreCategoryValidate.php create mode 100644 route/merchant/points.php diff --git a/app/common/dao/store/order/StoreOrderDao.php b/app/common/dao/store/order/StoreOrderDao.php index 7e8de38..99e0f66 100644 --- a/app/common/dao/store/order/StoreOrderDao.php +++ b/app/common/dao/store/order/StoreOrderDao.php @@ -291,6 +291,9 @@ class StoreOrderDao extends BaseDao ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) { $query->where('uid', $where['uid']); }) + ->when($where['activity_type'] == 20, function ($query) use ($where) { + $query->where('mer_id', $where['mer_id'] ?? 0); + }) ->when(isset($where['is_user']) && $where['is_user'] !== '', function ($query) use ($where) { $query->where(function($query) { $query->where('order_type',0)->whereOr(function($query){ diff --git a/app/common/repositories/store/order/PointsOrderCreateRepository.php b/app/common/repositories/store/order/PointsOrderCreateRepository.php index 2dea838..8457b3f 100644 --- a/app/common/repositories/store/order/PointsOrderCreateRepository.php +++ b/app/common/repositories/store/order/PointsOrderCreateRepository.php @@ -11,6 +11,7 @@ use app\common\repositories\store\product\ProductPresellSkuRepository; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\StoreDiscountRepository; use app\common\repositories\system\merchant\MerchantRepository; +use app\common\repositories\user\IntegralRepository; use app\common\repositories\user\UserAddressRepository; use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserMerchantRepository; @@ -24,7 +25,7 @@ class PointsOrderCreateRepository $key = md5(json_encode(compact('cartId', 'useIntegral', 'addressId'))) . $user->uid; $address = $this->validateAddress($user,$addressId); [$merchantCartList,$order_model,$order_extend,$order_type] = $this->validateCartList($cartId,$user,$address); - $successData = $this->validateMerchantList($merchantCartList); + $successData = $this->validateMerchantList($user,$merchantCartList); return $successData + [ 'key' => $key, 'order_type' => $order_type, @@ -103,7 +104,7 @@ class PointsOrderCreateRepository * @author Qinii * @day 2023/4/20 */ - public function validateMerchantList($merchantCartList) + public function validateMerchantList($user,$merchantCartList) { $deliveryStatus = true; $order_total_num = 0; @@ -145,6 +146,10 @@ class PointsOrderCreateRepository $cart['extension_two'] = 0; $cart['cost'] = $total_cost; } + // 判断:当前商户积分是否充足 + $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数 + if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分"); + unset($cart); if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) { $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus; @@ -328,27 +333,30 @@ class PointsOrderCreateRepository $storeCartRepository->updates($cartId, ['is_pay' => 1]); //创建订单 $groupOrder = $storeGroupOrderRepository->create($groupOrder); + // 减少积分 if ($groupOrder['integral'] > 0) { + foreach ($_orderList as $k => $order) { + foreach ($order['cartInfo']['list'] as $cart) { + // 减少对应的商户积分 + app()->make(IntegralRepository::class)->changeIntegral((int)$user['uid'],(int)$cart->mer_id,(float)sprintf("%.2f",0 - (int)$cart->integral)); + } + } + // 减少总持有积分 $user->integral = bcsub($user->integral, $groupOrder['integral'], 0); - $userBillRepository->decBill( - $user['uid'], - 'integral', - 'points_order', - [ - 'link_id' => $groupOrder['group_order_id'], - 'status' => 1, - 'title' => '积分商城兑换商品', - 'number' => $groupOrder['integral'], - 'mark' => '积分商城兑换商品使用积分' . floatval($groupOrder['integral']) , - 'balance' => $user->integral - ] - ); + $userBillRepository->decBill($user['uid'],'integral','points_order',[ + 'link_id' => $groupOrder['group_order_id'], + 'status' => 1, + 'title' => '积分商城兑换商品', + 'number' => $groupOrder['integral'], + 'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']), + 'balance' => $user->integral + ]); $user->save(); } + foreach ($_orderList as $k => $order) { $_orderList[$k]['group_order_id'] = $groupOrder->group_order_id; } - $orderProduct = []; $orderStatus = []; foreach ($_orderList as $order) { diff --git a/app/common/repositories/store/pionts/PointsProductRepository.php b/app/common/repositories/store/pionts/PointsProductRepository.php index 39ed48b..0f94206 100644 --- a/app/common/repositories/store/pionts/PointsProductRepository.php +++ b/app/common/repositories/store/pionts/PointsProductRepository.php @@ -295,6 +295,7 @@ class PointsProductRepository extends BaseRepository 'once_max_count' => $data['once_max_count'] ?? 0, 'pay_limit' => $data['pay_limit'] ?? 0, 'svip_price_type' => $data['svip_price_type'] ?? 0, + 'mer_id' => $data['mer_id'] ?? 0, ]; if (isset($data['product_type'])) $result['product_type'] = $data['product_type']; diff --git a/app/controller/merchant/points/Category.php b/app/controller/merchant/points/Category.php new file mode 100644 index 0000000..9ec950e --- /dev/null +++ b/app/controller/merchant/points/Category.php @@ -0,0 +1,100 @@ +repository = $repository; + } + + public function lst() + { + return app('json')->success($this->repository->getFormatList($this->request->merId(), null, 1)); + } + + /** + * @Author:Qinii + * @Date: 2020/5/11 + * @return mixed + */ + public function createForm() + { + return app('json')->success(formToData($this->repository->pointsForm(null))); + } + + /** + * @Author:Qinii + * @Date: 2020/5/11 + * @param validate $validate + * @return mixed + */ + public function create(validate $validate) + { + $data = $this->checkParams($validate); + $data['cate_name'] = trim($data['cate_name']); + if ($data['cate_name'] == '') return app('json')->fail('分类名不可为空'); + $data['mer_id'] = $this->request->merId(); + $this->repository->create($data); + return app('json')->success('添加成功'); + } + + public function updateForm($id) + { + if (!$this->repository->merExists($this->request->merId(), $id)) + return app('json')->fail('数据不存在'); + return app('json')->success(formToData($this->repository->pointsForm($id))); + } + + public function update($id, validate $validate) + { + $data = $this->checkParams($validate); + if (!$this->repository->merExists($this->request->merId(), $id)) + return app('json')->fail('数据不存在'); + $this->repository->update($id, $data); + return app('json')->success('编辑成功'); + } + + public function switchStatus($id) + { + $status = $this->request->param('status', 0) == 1 ? 1 : 0; + if (!$this->repository->merExists($this->request->merId(), $id)) + return app('json')->fail('数据不存在'); + $this->repository->switchStatus($id, $status); + return app('json')->success('修改成功'); + } + + public function delete($id) + { + if (!$this->repository->merExists($this->request->merId(), $id)) + return app('json')->fail('数据不存在'); + if ($this->repository->hasChild($id)) + return app('json')->fail('该分类存在子集,请先处理子集'); + + $this->repository->delete($id); + return app('json')->success('删除成功'); + } + + public function select() + { + return app('json')->success($this->repository->getAll($this->request->merId(),1,1)); + } + public function checkParams(validate $validate) + { + $data = $this->request->params(['cate_name','is_show','pic','sort','type',['pid',0]]); + $validate->check($data); + return $data; + } + +} diff --git a/app/controller/merchant/points/Order.php b/app/controller/merchant/points/Order.php new file mode 100644 index 0000000..f1e3570 --- /dev/null +++ b/app/controller/merchant/points/Order.php @@ -0,0 +1,187 @@ +repository = $repository; + } + + /** + * @Author:Qinii + * @Date: 2020/5/18 + * @return mixed + */ + public function lst() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['keyword', 'date','status','order_sn','product_id','nickname','phone','uid','store_name']); + $where['activity_type'] = 20; + $where['mer_id'] = $this->request->merId(); + if ($where['status'] == -10) { + unset($where['status']); + $where['is_del'] = 1; + } + return app('json')->success($this->repository->pointsOrderAdminList($where, $page, $limit)); + } + + /** + * @param $id + * @return mixed + * @author Qinii + * @day 2020-06-11 + */ + public function detail($id) + { + $data = $this->repository->getOne($id, $this->request->merId()); + if (!$data) return app('json')->fail('数据不存在'); + return app('json')->success($data); + } + + public function getStatus($id) + { + [$page, $limit] = $this->getPage(); + $where['user_type'] = $this->request->param('user_type'); + $where['date'] = $this->request->param('date'); + $where['id'] = $id; + $data = $this->repository->getOrderStatus($where, $page, $limit); + if (!$data) return app('json')->fail('数据不存在'); + return app('json')->success($data); + } + + /** + * TODO 发货 + * @param $id + * @return mixed + * @author Qinii + */ + public function delivery($id) + { + $split = $this->request->params(['is_split',['split',[]]]); + if (!$this->repository->merDeliveryExists($id, $this->request->merId())) + return app('json')->fail('订单信息或状态错误'); + $data = $this->request->params([ + 'delivery_type', + 'delivery_name', + 'delivery_id', + 'remark', + ]); + if (!$data['delivery_type'] || $data['delivery_type'] != 3 && (!$data['delivery_name'] || !$data['delivery_id'])) + return app('json')->fail('填写配送信息'); + + $this->repository->runDelivery($id,$this->request->merId(), $data, $split, 'delivery'); + return app('json')->success('发货成功'); + } + + /** + * TODO + * @return \think\response\Json + * @author Qinii + * @day 7/26/21 + */ + public function batchDelivery() + { + $params = $this->request->params([ + 'order_id', + 'delivery_id', + 'delivery_type', + 'delivery_name', + 'remark', + ]); + if (!in_array($params['delivery_type'], [1,2,3])) + return app('json')->fail('发货类型错误'); + if (!$params['order_id']) + return app('json')->fail('需要订单ID'); + $data = ['mer_id' => $this->request->merId(), 'data' => $params]; + Queue::push(BatchDeliveryJob::class, $data); + return app('json')->success('开始批量发货'); + } + + /** + * TODO 导出文件 + * @author Qinii + * @day 2020-07-30 + */ + public function excel() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['keyword','date','status','order_sn','product_id']); + $data = app()->make(ExcelService::class)->pointsOrder($where,$page,$limit); + return app('json')->success($data); + } + + /** + * @Author:Qinii + * @Date: 2020/5/18 + * @param $id + * @return mixed + */ + public function delete($id) + { + if (!$this->repository->userDelExists($id, $this->request->merId())) + return app('json')->fail('订单信息或状态错误'); + $this->repository->update($id,['is_system_del' => 1]); + return app('json')->success('删除成功'); + } + + /** + * @param $id + * @return mixed + * @author Qinii + * @day 2020-06-11 + */ + public function remarkForm($id) + { + return app('json')->success(formToData($this->repository->pointsMarkForm($id))); + } + + /** + * @param $id + * @return mixed + * @author Qinii + * @day 2020-06-11 + */ + public function remark($id) + { + if (!$this->repository->getOne($id, $this->request->merId())) + return app('json')->fail('数据不存在'); + $data = $this->request->params(['remark']); + $this->repository->update($id, $data); + + return app('json')->success('备注成功'); + } + + public function express($id) + { + if (!$this->repository->getWhereCount(['order_id' => $id])) + return app('json')->fail('订单信息或状态错误'); + return app('json')->success($this->repository->express($id,$this->request->merId())); + } + +} diff --git a/app/controller/merchant/points/Product.php b/app/controller/merchant/points/Product.php new file mode 100644 index 0000000..0a9ec18 --- /dev/null +++ b/app/controller/merchant/points/Product.php @@ -0,0 +1,187 @@ +repository = $repository; + } + + /** + * @Author:Qinii + * @Date: 2020/5/18 + * @return mixed + */ + public function lst() + { + [$page, $limit] = $this->getPage(); + $where = $this->request->params(['cate_id', 'keyword', 'is_used', 'date','store_name']); + return app('json')->success($this->repository->getAdminList($this->request->merId(), $where, $page, $limit)); + } + + + public function create() + { + $data = $this->checkParams(); + $this->repository->create($data, $this->repository::PRODUCT_TYPE_POINTS); + return app('json')->success('添加成功'); + } + + /** + * @Author:Qinii + * @Date: 2020/5/18 + * @return mixed + */ + public function getStatusFilter() + { + return app('json')->success($this->repository->getFilter(null,'商品',0)); + } + + /** + * @Author:Qinii + * @Date: 2020/5/18 + * @param $id + * @return mixed + */ + public function detail($id) + { + return app('json')->success($this->repository->detail($id)); + } + + /** + * @Author:Qinii + * @Date: 2020/5/11 + * @param $id + * @param validate $validate + * @return mixed + */ + public function update($id) + { + $data = $this->checkParams(); + $this->repository->edit($id,$data,$this->request->merId(),$this->repository::PRODUCT_TYPE_POINTS); + return app('json')->success('编辑成功'); + } + + /** + * TODO 上 / 下架 + * @Author:Qinii + * @Date: 2020/5/18 + * @param int $id + * @return mixed + */ + public function switchStatus($id) + { + if(!$this->repository->merExists(null,$id)) + return app('json')->fail('数据不存在'); + $status = $this->request->param('status',0) == 1 ? 1 : 0; + $this->repository->switchShow($id,$status,'is_used'); + return app('json')->success('修改成功'); + } + + /** + * @Author:Qinii + * @Date: 2020/5/18 + * @param $id + * @return mixed + */ + public function delete($id) + { + if(!$this->repository->merExists($this->request->merId(),$id)) + return app('json')->fail('数据不存在'); + $this->repository->destory($id); + return app('json')->success('删除成功'); + } + /** + * @Author:Qinii + * @Date: 2020/5/11 + * @param validate $validate + * @return array + */ + public function checkParams() + { + $data = $this->request->params($this->repository::CREATE_PARAMS); + $data['mer_status'] = 1; + $data['delivery_way'] = [2]; + $data['delivery_free'] = 1; + $data['is_used'] = $this->request->param('is_used',0); + $data['is_hot'] = $this->request->param('is_hot',0); + $data['is_show'] = 1; + $data['status'] = 1; + $data['pay_limit'] = 2; + $data['product_type'] = $this->repository::PRODUCT_TYPE_POINTS; + $data['mer_id'] = $this->request->merId(); + app()->make(StoreProductValidate::class)->check($data); + return $data; + } + + /** + * TODO + * @param $id + * @return \think\response\Json + * @author Qinii + * @day 3/17/21 + */ + public function updateSort($id) + { + $sort = $this->request->param('sort'); + $this->repository->updateSort($id,null,['rank' => $sort]); + return app('json')->success('修改成功'); + } + + + /** + * TODO 批量显示隐藏 + * @return \think\response\Json + * @author Qinii + * @day 2022/11/14 + */ + public function batchShow() + { + $ids = $this->request->param('ids'); + $status = $this->request->param('status') == 1 ? 1 : 0; + $this->repository->batchSwitchShow($ids,$status,'is_used',0); + return app('json')->success('修改成功'); + } + + public function isFormatAttr($id) + { + $data = $this->request->params([ + ['attrs', []], + ['items', []], + ['product_type', 0] + ]); + $data = app()->make(ProductRepository::class)->isFormatAttr($data['attrs'],$id,$data['product_type']); + return app('json')->success($data); + } + + public function preview() + { + $data = $this->request->param(); + return app('json')->success($this->repository->preview($data)); + } + + +} diff --git a/app/validate/merchant/StoreCategoryValidate.php b/app/validate/merchant/StoreCategoryValidate.php new file mode 100644 index 0000000..0999641 --- /dev/null +++ b/app/validate/merchant/StoreCategoryValidate.php @@ -0,0 +1,22 @@ + 'require|integer', + 'cate_name|分类名称' => 'require|max:12', + 'is_show|状态' => 'require|in:0,1', + 'pic|分类图标' => 'max:128', + 'sort|排序' => 'require|integer' + ]; +} diff --git a/route/merchant/points.php b/route/merchant/points.php new file mode 100644 index 0000000..6c3adad --- /dev/null +++ b/route/merchant/points.php @@ -0,0 +1,122 @@ +name('pointsCateLst')->option([ + '_alias' => '列表', + ]); + Route::get('detail/:id', '/detail')->name('pointsCateDetail')->option([ + '_alias' => '详情', + ]); + Route::get('select', '/select')->option([ + '_alias' => '筛选', + ]); + Route::post('create', '/create')->name('pointsCateCreate')->option([ + '_alias' => '添加', + ]); + Route::post('update/:id', '/update')->name('pointsCateUpdate')->option([ + '_alias' => '编辑', + ]); + Route::get('create/form', '/createForm')->name('pointsCateCreateForm')->option([ + '_alias' => '添加表单', + '_auth' => false, + '_form' => 'pointsCateCreate', + ]); + Route::get('update/form/:id', '/updateForm')->name('pointsCateUpdateForm')->option([ + '_alias' => '编辑表单', + '_auth' => false, + '_form' => 'pointsCateUpdate', + ]); + Route::post('status/:id', '/switchStatus')->name('pointsCateStatus')->option([ + '_alias' => '修改状态', + ]); + Route::delete('delete/:id', '/delete')->name('pointsCateStatus')->option([ + '_alias' => '修改状态', + ]); + })->prefix('merchant.points.Category')->option([ + '_path' => '/marketing/integral/classify', + '_auth' => true, + ]); + // 积分商品管理 + Route::group('points/product', function () { + Route::get('lst', '/lst')->name('pointsProductLst')->option([ + '_alias' => '列表', + ]); + Route::post('get_attr_value/:id', '/isFormatAttr')->name('pointsCateFormatAttr')->option([ + '_alias' => '获取规格', + ]); + Route::get('detail/:id', '/detail')->name('pointsProductDetail')->option([ + '_alias' => '编辑', + ]); + Route::post('create', '/create')->name('pointsProductCreate')->option([ + '_alias' => '添加', + ]); + Route::post('update/:id', '/update')->name('pointsProductUpdate')->option([ + '_alias' => '编辑', + ]); + Route::post('status/:id', '/switchStatus')->name('pointsProductStatus')->option([ + '_alias' => '修改状态', + ]); + Route::delete('delete/:id', '/delete')->name('pointsProductStatus')->option([ + '_alias' => '修改状态', + ]); + Route::post('preview', '/preview')->name('pointsProductPreview')->option([ + '_alias' => '预览', + ]); + })->prefix('merchant.points.Product')->option([ + '_path' => '/marketing/integral/proList', + '_auth' => true, + ]); + // 积分商品订单 + Route::group('points/order', function () { + Route::get('lst', '/lst')->name('pointsOrderLst')->option([ + '_alias' => '列表', + ]); + Route::get('detail/:id', '/detail')->name('pointsOrderDetail')->option([ + '_alias' => '编辑', + ]); + Route::post('delivery/:id', '/delivery')->name('pointsOrderDelivery')->option([ + '_alias' => '发货', + ]); + Route::post('delivery_batch', '/batchDelivery')->name('pointsOrderBatchDelivery')->option([ + '_alias' => '批量发货', + ]); + Route::get('express/:id', '/express')->name('pointsOrderExpress')->option([ + '_alias' => '快递查询', + ]); + Route::get('excel', '/Excel')->name('pointsOrderExcel')->option([ + '_alias' => '导出', + ]); + Route::get('mark/:id/form', '/remarkForm')->name('pointsOrderMarkForm')->option([ + '_alias' => '备注表单', + '_auth' => false, + '_form' => 'pointsOrderMark', + ]); + Route::post('mark/:id', '/remark')->name('pointsOrderMark')->option([ + '_alias' => '备注', + ]); + Route::get('status/:id', '/getStatus')->name('pointsOrderStatus')->option([ + '_alias' => '记录', + ]); + Route::delete('delete/:id', '/delete')->name('pointsOrderDelete')->option([ + '_alias' => '删除', + ]); + })->prefix('merchant.points.Order')->option([ + '_path' => '/marketing/integral/orderList', + '_auth' => true, + ]); + +})->middleware(AllowOriginMiddleware::class) + ->middleware(MerchantTokenMiddleware::class, true) + ->middleware(MerchantAuthMiddleware::class) + ->middleware(MerchantCheckBaseInfoMiddleware::class) + ->middleware(LogMiddleware::class);