diff --git a/app/common/dao/store/StoreActivityOrderDao.php b/app/common/dao/store/StoreActivityOrderDao.php index 1d5f8c6e..e212cca6 100644 --- a/app/common/dao/store/StoreActivityOrderDao.php +++ b/app/common/dao/store/StoreActivityOrderDao.php @@ -39,8 +39,8 @@ class StoreActivityOrderDao extends BaseDao ->find(); if (!empty($consumptionDetail['amount'])) { // 当前订单使用现金抵扣红包 或 使用通用红包后实付金额不足红包金额的1.5倍,视为无效订单 - $redPackType = StoreConsumptionUser::where('coupon_id', $consumptionDetail['coupon_user_id'])->value('type'); - if ($redPackType == StoreConsumptionUser::TYPE_TWO || $consumptionDetail['pay_price'] < $consumptionDetail['amount'] * 1.5) { + $redPackType = StoreConsumptionUser::where('coupon_user_id', $consumptionDetail['coupon_user_id'])->value('type'); + if ($redPackType == StoreConsumptionUser::TYPE_TWO || ($redPackType == StoreConsumptionUser::TYPE_TWO && $consumptionDetail['pay_price'] < $consumptionDetail['amount'] * 1.5)) { $model->status = StoreActivityOrder::STATUS_INVALID; } } diff --git a/app/common/dao/store/StoreActivityUserDao.php b/app/common/dao/store/StoreActivityUserDao.php index 2a99f9d6..0c1dbd03 100644 --- a/app/common/dao/store/StoreActivityUserDao.php +++ b/app/common/dao/store/StoreActivityUserDao.php @@ -112,23 +112,36 @@ class StoreActivityUserDao extends BaseDao $consumption = StoreConsumption::where('coupon_id', $activityUser['value']) ->where('type', StoreConsumption::TYPE_PULL_CONSUMPTION) ->find(); + $unReceiveConsumption = StoreConsumptionUser::where('uid', $userId)->where('status', StoreConsumptionUser::STATUS_UN_RECEIVE)->value('order_id_set'); + if (!empty($unReceiveConsumption)) { + $groupOrderIds = explode(',', $unReceiveConsumption); + $groupOrderId = $groupOrderIds[0]; + $myOrderWhere = ['group_order_id' => $groupOrderId]; + } else { + $myOrderWhere = ['status' => StoreActivityOrder::STATUS_VALID]; + } $myOrder = StoreActivityOrder::where('user_id', $userId) ->where('activity_id', $activityId) - ->where('status', StoreActivityOrder::STATUS_VALID) + ->where($myOrderWhere) ->find(); - if (empty($myOrder)) { + if (empty($myOrder) || empty($myOrder['pay_price'])) { return ['target' => $target, 'allow_receive' => false, 'user_info' => $userInfo]; } - $storeConsumptionUserDao = new StoreConsumptionUserDao(); - $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['total_amount']); $userInfo = User::where('spread_uid', $userId)->field('uid,nickname,avatar')->select()->toArray(); - $orders = StoreActivityOrder::where('spread_id', $userId) + $storeConsumptionUserDao = new StoreConsumptionUserDao(); + $scope = $storeConsumptionUserDao->getScope($consumption, $myOrder['pay_price']); + $orderQuery = StoreActivityOrder::where('spread_id', $userId) ->whereIn('user_id', array_column($userInfo, 'uid')) ->where('activity_id', $activityId) ->where('is_first_order', StoreActivityOrder::IS_FIRST_ORDER) - ->where('total_amount', '>=', $scope['start']) - ->where('status', StoreActivityOrder::STATUS_VALID) - ->select()->toArray(); + ->where('pay_price', '>=', $scope['start']); + if (!empty($groupOrderIds)) { + unset($groupOrderIds[0]); + $orderQuery->whereIn('group_order_id', $groupOrderIds); + } else { + $orderQuery->where('status', StoreActivityOrder::STATUS_VALID); + } + $orders = $orderQuery->select()->toArray(); $orders = reset_index($orders, 'user_id'); foreach ($userInfo as &$user) { $user['target_amount'] = $scope['start']; @@ -183,13 +196,19 @@ class StoreActivityUserDao extends BaseDao ->whereIn('type', $type) ->where('status', StoreConsumptionUser::STATUS_UNUSED) ->sum('balance'); - $query = UserBill::with('storeConsumptionUser') - ->field('link_id,create_time') + $query = UserBill::field('link_id,create_time,number coupon_price,mark') ->where('uid', $userId) ->where('category', 'red_pack') ->where('type', "red_pack_{$type}"); $count = $query->count(); $record = $query->page($page)->limit($limit)->select()->toArray(); + foreach ($record as &$item) { + $item['order_amount'] = 0; + if (mb_strpos($item['mark'], '订单金额:') !== false) { + $item['order_amount'] = mb_substr($item['mark'], mb_strpos($item['mark'], '订单金额:') + 5); + } + unset($item['mark']); + } return ['total_amount' => $totalAmount, 'count' => $count, 'record' => $record]; } @@ -206,10 +225,24 @@ class StoreActivityUserDao extends BaseDao ->field('SUM(balance) as total_amount,type') ->group('type') ->select()->toArray(); - foreach ($totalAmount as &$item) { + $totalAmount = reset_index($totalAmount, 'type'); + $result = [ + [ + 'type' => 1, + 'total_amount' => 0.00 + ], + [ + 'type' => 2, + 'total_amount' => 0.00 + ] + ]; + foreach ($result as &$item) { + if (isset($totalAmount[$item['type']])) { + $item['total_amount'] = $totalAmount[$item['type']]['total_amount']; + } $item['type_cn'] = StoreConsumptionUser::TYPE_MAP[$item['type']]; } - return $totalAmount; + return $result; } } diff --git a/app/common/dao/store/consumption/StoreConsumptionDao.php b/app/common/dao/store/consumption/StoreConsumptionDao.php index 5e375f1e..bc4b3162 100644 --- a/app/common/dao/store/consumption/StoreConsumptionDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionDao.php @@ -25,7 +25,15 @@ class StoreConsumptionDao extends BaseDao */ public function getValidList() { - return StoreConsumption::whereIn('type', [StoreConsumption::TYPE_OWNER_CONSUMPTION, StoreConsumption::TYPE_PULL_CONSUMPTION])->where('status', StoreConsumption::STATUS_ENABLE)->field('coupon_id,start_time,end_time,title')->select(); + return StoreConsumption::whereIn('type', [StoreConsumption::TYPE_OWNER_CONSUMPTION, StoreConsumption::TYPE_PULL_CONSUMPTION])->where('status', StoreConsumption::STATUS_ENABLE) + ->field('coupon_id,start_time,end_time,title')->select()->each(function ($item){ + if($item['title']=='无门槛实物通用红包'){ + $item['title'] = '用户推荐拉新活动'; + }else{ + $item['title'] = '用户消费补贴活动'; + } + return $item; + }); } public function getOne($id) diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index 511d3c50..75ab40a9 100644 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -65,7 +65,7 @@ class StoreConsumptionUserDao extends BaseDao $orderValidAmount = min($groupOrder['pay_price'], $this->maxAmount); $scope = $this->getScope($consumption, $orderValidAmount); //用户没有达到 消费金活动 任一档次 - if ($scope['rate'] <= 0) { + if (empty($scope) || $scope['rate'] <= 0) { return false; } Db::startTrans(); @@ -73,7 +73,7 @@ class StoreConsumptionUserDao extends BaseDao $isFirstOrder = $this->isFirstOrder($userId, $consumption['start_time'], date('Y-m-d H:i:s', $endTime)); $storeActivityOrderDao = new StoreActivityOrderDao(); $storeActivityOrder = $storeActivityOrderDao->save($groupOrder, $spreadUserId, $isFirstOrder); - if ($consumption['type'] == StoreConsumption::TYPE_OWNER_CONSUMPTION && $storeActivityOrder['status'] == StoreActivityOrder::STATUS_VALID) { + if ($consumption['type'] == StoreConsumption::TYPE_OWNER_CONSUMPTION && $storeActivityOrder['status'] == StoreActivityOrder::STATUS_VALID && $storeActivityOrder['red_pack'] == 0) { $this->send($consumption, $scope['rate'], $userId, $groupOrder['group_order_id'], $orderValidAmount, StoreConsumptionUser::STATUS_UNUSED); $this->send($consumption, $scope['rate_two'], $userId, $groupOrder['group_order_id'], $orderValidAmount, StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO); $storeActivityOrderDao->repeal($groupOrder['group_order_id']); @@ -198,6 +198,7 @@ class StoreConsumptionUserDao extends BaseDao */ public function send($consumption, float $rate, int $userId, string $groupOrderIds, float $amount, $status = -2, $type = 1) { + $title = $type == StoreConsumptionUser::TYPE_TWO ? '现金抵扣红包' : '无门槛实物通用红包'; $model = StoreConsumptionUser::where('uid', $userId)->where('type', StoreConsumptionUser::TYPE_TWO)->find(); $couponPrice = bcmul($amount, $rate, 2); if (!empty($model) && $model['type'] == $type) { @@ -207,7 +208,7 @@ class StoreConsumptionUserDao extends BaseDao $model = new StoreConsumptionUser(); $model->coupon_id = $consumption['coupon_id']; $model->uid = $userId; - $model->coupon_title = $consumption['title']; + $model->coupon_title = $title; $model->order_id_set = $groupOrderIds; $model->coupon_price = $couponPrice; $model->balance = $model->coupon_price; @@ -221,7 +222,6 @@ class StoreConsumptionUserDao extends BaseDao if (!$model->save()) { throw new \Exception('发放失败'); } - $title = $type == StoreConsumptionUser::TYPE_TWO ? '现金抵扣红包' : '无门槛实物通用红包'; // 写入红包日志 /** @var $userBillRepository UserBillRepository */ $userBillRepository = app()->make(UserBillRepository::class); @@ -230,7 +230,7 @@ class StoreConsumptionUserDao extends BaseDao 'status' => 1, 'title' => '获得' . $title, 'number' => $couponPrice, - 'mark' => '获得' . $title . $couponPrice, + 'mark' => '获得' . $title . $couponPrice . ",订单金额:{$amount}", 'balance' => 0 ]); } @@ -258,4 +258,25 @@ class StoreConsumptionUserDao extends BaseDao return strtotime('+1 year', strtotime($datetime)); } -} \ No newline at end of file + /** + * 扣减红包余额 + * @param $id + * @param $amount + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function reduce($id, $amount) + { + $storeConsumptionUser = StoreConsumptionUser::where('coupon_user_id', $id)->find(); + if (empty($storeConsumptionUser) || $storeConsumptionUser->balance < $amount) { + throw new \Exception('红包余额不足'); + } + $balance = bcsub($storeConsumptionUser->balance, $amount, 2); + $storeConsumptionUser->balance = max($balance, 0); + if (!$storeConsumptionUser->save()) { + throw new \Exception('红包余额更新出错'); + } + } + +} diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 972be47b..73c6e7f2 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -35,10 +35,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository { protected $store_consumption_user; protected $consumption_money; + protected $balance; public function v2CartIdByOrderInfo($user, array $cartId, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, $createOrder = false, $consumption_id = 0) { $uid = $user->uid; + $this->balance = 0; $userIntegral = $user->integral; $key = md5(json_encode(compact('cartId', 'takes', 'useCoupon', 'useIntegral', 'addressId'))) . $uid; app()->make(StoreCouponUserRepository::class)->failCoupon(); @@ -154,6 +156,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository if ($consumption_id > 0) { $this->store_consumption_user = Db::name('store_consumption_user')->where('coupon_user_id', $consumption_id)->where('uid', $uid)->find(); + $this->balance=$this->store_consumption_user['balance']; } // 循环计算每个店铺的订单数据 委托商品是否设置收货方式 ? foreach ($merchantCartList as &$merchantCart) { @@ -446,7 +449,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'platformCoupon' => $platformCoupon, 'svip_coupon_merge' => $svip_coupon_merge, 'postage_price' => $postage_price, - 'isTake' => intval($allowDelivery == false), + 'isTake' => intval($allowDelivery == false || count($takes) > 0), 'total_num' => $total_num, 'enabledCoupon' => $enabledCoupon, 'useCouponIds' => $useCouponIds, @@ -565,33 +568,33 @@ class StoreOrderCreateRepository extends StoreOrderRepository $pay_price = $org_price; } //计算总红包金额 - $a = 0; - if ($consumption_id > 0) { + if ($consumption_id > 0 ) { if ($this->store_consumption_user) { - if ($this->store_consumption_user['type'] == 2) { + if ($this->store_consumption_user['type'] == 2 && $pay_price>=6) { $a = bcdiv($pay_price, 6); - if ($this->store_consumption_user['balance'] > $a) { + if ($this->balance > $a) { $pay_price = bcsub($pay_price, $a, 2); - $this->consumption_money = bcadd($this->consumption_money, $a); - $this->store_consumption_user['balance'] = bcsub($this->store_consumption_user['balance'], $a); + $this->consumption_money = bcadd($this->consumption_money, $a, 2); + $this->balance = bcsub($this->balance, $a, 2); } else { - $a = $this->store_consumption_user['balance']; - $pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2); - $this->consumption_money = bcadd($this->consumption_money, $this->store_consumption_user['balance']); - $this->store_consumption_user['balance'] = 0; + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); + $this->balance = 0; } } if ($this->store_consumption_user['type'] == 1) { - if ($pay_price > $this->store_consumption_user['balance']) { - $pay_price = bcsub($pay_price, $this->store_consumption_user['balance'], 2); - $this->consumption_money = $this->store_consumption_user['balance']; - $a = $this->store_consumption_user['balance']; + if ($pay_price > $this->balance) { + $pay_price = bcsub($pay_price, $this->balance, 2); + $this->consumption_money = bcadd($this->consumption_money, $this->balance, 2); + $this->balance=0; } else { $this->consumption_money = $pay_price; + $this->balance = bcsub($this->balance, $pay_price, 2); $pay_price = 0; - $a = $this->consumption_money; + } } + } } @@ -611,7 +614,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; $merchantCart['order']['consumption_id'] = $consumption_id; - $merchantCart['order']['consumption_money'] = $a; + $merchantCart['order']['consumption_money'] = $this->consumption_money; $order_price = bcadd($order_price, $pay_price, 2); $order_total_price = bcadd($order_total_price, $total_price, 2); @@ -638,7 +641,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0; $total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2); $is_self_pickup = true; - if($order_type=='balance' &&$source!=103){ + if($order_type=='balance' &&$source!=103 && $createOrder==true){ throw new ValidateException('余额支付只能用于里海云仓'); } return compact( diff --git a/app/common/repositories/user/UserRepository.php b/app/common/repositories/user/UserRepository.php index 8c16a1b3..5eacd8c5 100644 --- a/app/common/repositories/user/UserRepository.php +++ b/app/common/repositories/user/UserRepository.php @@ -673,6 +673,10 @@ class UserRepository extends BaseRepository ]; if($code){ $data['promotion_code']=$code; + $shop=explode('shop_',$code); + if(count($shop)==2){ + $data['spread_uid']=$shop[1]; + } Cache::delete('promote_'.$ip); } return $this->create($user_type, $data); diff --git a/app/controller/admin/store/StoreProduct.php b/app/controller/admin/store/StoreProduct.php index bbdf129a..72d5bc71 100644 --- a/app/controller/admin/store/StoreProduct.php +++ b/app/controller/admin/store/StoreProduct.php @@ -18,6 +18,7 @@ use think\App; use crmeb\basic\BaseController; use app\validate\merchant\StoreProductAdminValidate as validate; use app\common\repositories\store\product\ProductRepository as repository; +use think\facade\Db; use think\facade\Queue; class StoreProduct extends BaseController @@ -49,11 +50,11 @@ class StoreProduct extends BaseController public function lst() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid','store_name','is_trader','us_status','product_id','star','sys_labels','hot_type','svip_price_type']); - $mer_id = $this->request->param('mer_id',''); + $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'pid', 'store_name', 'is_trader', 'us_status', 'product_id', 'star', 'sys_labels', 'hot_type', 'svip_price_type']); + $mer_id = $this->request->param('mer_id', ''); $merId = $mer_id ? $mer_id : null; $where['is_gift_bag'] = 0; - $_where = $this->repository->switchType($where['type'], null,0); + $_where = $this->repository->switchType($where['type'], null, 0); unset($_where['product_type']); unset($_where['star']); $where = array_merge($where, $_where); @@ -68,14 +69,14 @@ class StoreProduct extends BaseController public function bagList() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['cate_id','keyword',['type',1],'mer_cate_id' ,'is_trader','us_status']); + $where = $this->request->params(['cate_id', 'keyword', ['type', 1], 'mer_cate_id', 'is_trader', 'us_status']); $merId = $this->request->param('mer_id') ? $this->request->param('mer_id') : null; - $_where = $this->repository->switchType($where['type'], null,10); - $where = array_merge($where,$_where); + $_where = $this->repository->switchType($where['type'], null, 10); + $where = array_merge($where, $_where); $where['order'] = 'rank'; unset($where['star']); - return app('json')->success($this->repository->getAdminList($merId,$where, $page, $limit)); + return app('json')->success($this->repository->getAdminList($merId, $where, $page, $limit)); } /** @@ -85,7 +86,7 @@ class StoreProduct extends BaseController */ public function getStatusFilter() { - return app('json')->success($this->repository->getFilter(null,'商品',[0,98])); + return app('json')->success($this->repository->getFilter(null, '商品', [0, 98])); } /** @@ -96,7 +97,7 @@ class StoreProduct extends BaseController */ public function getBagStatusFilter() { - return app('json')->success($this->repository->getFilter(null,'礼包',10)); + return app('json')->success($this->repository->getFilter(null, '礼包', 10)); } /** @@ -107,9 +108,9 @@ class StoreProduct extends BaseController */ public function detail($id) { - if(!$this->repository->merExists(null,$id)) + if (!$this->repository->merExists(null, $id)) return app('json')->fail('数据不存在'); - return app('json')->success($this->repository->getAdminOneProduct($id,0)); + return app('json')->success($this->repository->getAdminOneProduct($id, 0)); } /** @@ -119,10 +120,10 @@ class StoreProduct extends BaseController * @param validate $validate * @return mixed */ - public function update($id,validate $validate) + public function update($id, validate $validate) { $data = $this->checkParams($validate); - $this->repository->adminUpdate($id,$data); + $this->repository->adminUpdate($id, $data); return app('json')->success('编辑成功'); } @@ -137,14 +138,14 @@ class StoreProduct extends BaseController { //0:审核中,1:审核通过 -1: 未通过 -2: 下架 $id = $this->request->param('id'); - $data = $this->request->params(['status','refusal']); - if (in_array($data['status'],[1,0,-2,-1])) - if($data['status'] == -1 && empty($data['refusal'])) - return app('json')->fail('请填写拒绝理由'); - if(is_array($id)) { - $this->repository->batchSwitchStatus($id,$data); + $data = $this->request->params(['status', 'refusal']); + if (in_array($data['status'], [1, 0, -2, -1])) + if ($data['status'] == -1 && empty($data['refusal'])) + return app('json')->fail('请填写拒绝理由'); + if (is_array($id)) { + $this->repository->batchSwitchStatus($id, $data); } else { - $this->repository->switchStatus($id,$data); + $this->repository->switchStatus($id, $data); } return app('json')->success('操作成功'); } @@ -159,7 +160,7 @@ class StoreProduct extends BaseController */ public function checkParams(validate $validate) { - $data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','content','rank','star']); + $data = $this->request->params(['is_hot', 'is_best', 'is_benefit', 'is_new', 'store_name', 'content', 'rank', 'star']); $validate->check($data); return $data; } @@ -171,14 +172,14 @@ class StoreProduct extends BaseController */ public function checkProduct() { - Queue::push(CheckProductExtensionJob::class,[]); + Queue::push(CheckProductExtensionJob::class, []); return app('json')->success('后台已开始检测'); } public function lists() { $make = app()->make(MerchantRepository::class); - $data = $make->selectWhere(['is_del' => 0],'mer_id,mer_name'); + $data = $make->selectWhere(['is_del' => 0], 'mer_id,mer_name'); return app('json')->success($data); } @@ -191,7 +192,7 @@ class StoreProduct extends BaseController */ public function addFictiForm($id) { - if(!$this->repository->merExists(null,$id)) + if (!$this->repository->merExists(null, $id)) return app('json')->fail('数据不存在'); return app('json')->success(formToData($this->repository->fictiForm($id))); } @@ -206,18 +207,18 @@ class StoreProduct extends BaseController */ public function addFicti($id) { - $data = $this->request->params(['type','ficti']); - if(!in_array($data['type'],[1,2])) return app('json')->fail('类型错误'); - if(!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0'); - $res = $this->repository->getWhere(['product_id' => $id],'ficti,sales'); - if(!$res) return app('json')->fail('数据不存在'); - if($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足'); + $data = $this->request->params(['type', 'ficti']); + if (!in_array($data['type'], [1, 2])) return app('json')->fail('类型错误'); + if (!$data['ficti'] || $data['ficti'] < 0) return app('json')->fail('已售数量必须大于0'); + $res = $this->repository->getWhere(['product_id' => $id], 'ficti,sales'); + if (!$res) return app('json')->fail('数据不存在'); + if ($data['type'] == 2 && $res['ficti'] < $data['ficti']) return app('json')->fail('已售数量不足'); $ficti = ($data['type'] == 1) ? $data['ficti'] : '-' . $data['ficti']; $data = [ 'ficti' => $res['ficti'] + $ficti, 'sales' => $res['sales'] + $ficti ]; - $this->repository->update($id,$data); + $this->repository->update($id, $data); return app('json')->success('修改成功'); } @@ -231,14 +232,14 @@ class StoreProduct extends BaseController public function updateSort($id) { $sort = $this->request->param('sort'); - $this->repository->updateSort($id,null,['rank' => $sort]); + $this->repository->updateSort($id, null, ['rank' => $sort]); return app('json')->success('修改成功'); } public function setLabels($id) { $data = $this->request->params(['sys_labels']); - app()->make(SpuRepository::class)->setLabels($id,0,$data,0); + app()->make(SpuRepository::class)->setLabels($id, 0, $data, 0); return app('json')->success('修改成功'); } @@ -251,10 +252,10 @@ class StoreProduct extends BaseController */ public function changeUsed($id) { - if(!$this->repository->merExists(null,$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',0); + $status = $this->request->param('status', 0) == 1 ? 1 : 0; + $this->repository->switchShow($id, $status, 'is_used', 0); return app('json')->success('修改成功'); } @@ -268,7 +269,7 @@ class StoreProduct extends BaseController { $ids = $this->request->param('ids'); $status = $this->request->param('status') == 1 ? 1 : 0; - $this->repository->batchSwitchShow($ids,$status,'is_used',0); + $this->repository->batchSwitchShow($ids, $status, 'is_used', 0); return app('json')->success('修改成功'); } @@ -283,7 +284,7 @@ class StoreProduct extends BaseController $ids = $this->request->param('ids'); $data = $this->request->params(['sys_labels']); if (empty($ids)) return app('json')->fail('请选择商品'); - app()->make(SpuRepository::class)->batchLabels($ids, $data,0); + app()->make(SpuRepository::class)->batchLabels($ids, $data, 0); return app('json')->success('修改成功'); } @@ -296,17 +297,33 @@ class StoreProduct extends BaseController public function batchHot() { $ids = $this->request->param('ids'); - $data = $this->request->params([['is_hot',0],['is_benefit',0],['is_best',0],['is_new',0]]); + $data = $this->request->params([['is_hot', 0], ['is_benefit', 0], ['is_best', 0], ['is_new', 0]]); if (empty($ids)) return app('json')->fail('请选择商品'); - $this->repository->updates($ids,$data); + $this->repository->updates($ids, $data); return app('json')->success('修改成功'); } - public function copy(){ - $product=$this->repository->getAdminOneProduct(6300,0); - $product = $product->toArray(); - $product['mer_id']=113; - $product['old_product_id']=$product['product_id']; - return $this->repository->create($product, 0,1); - + //**复制商品 */ + public function copy($product_id = 0, $mer_id = 0, $street_code = 0, $type_id = 0, $category_id = 0) + { + if ($product_id == 0) return app('json')->fail('参数错误'); + $products = $this->repository->getAdminOneProduct($product_id, 0); + $product = $products->toArray(); + $product['mer_id'] = $mer_id; + $product['old_product_id'] = $product['product_id']; + $productId = $this->repository->create($product, 0, 1); + $data = [ + 'product_id' => $productId, + 'mer_id' => $mer_id, + 'source_mer_id' => $products['mer_id'], + 'street_code' => $street_code, + 'weight' => 1, + 'status' => 1, + 'create_time' => date('Y-m-d H:i:s'), + 'type_id' => $type_id, + 'category_id' => $category_id, + 'cate_id' => $product['cate_id'] + ]; + Db::name('cloud_product')->insert($data); + return $productId; } } diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 0048b4e2..dfe0b51e 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -410,6 +410,7 @@ class Auth extends BaseController }else{ $data['show_controller_applet']=false; } + $data['red_pack_balance']=Db::name('store_consumption_user')->where('uid',$data['uid'])->where('status',0)->sum('balance'); return app('json')->success($data); } diff --git a/app/controller/api/Common.php b/app/controller/api/Common.php index 816eea9d..cbd5aa15 100644 --- a/app/controller/api/Common.php +++ b/app/controller/api/Common.php @@ -644,7 +644,7 @@ class Common extends BaseController public function Qrcode($data) { $siteUrl = systemConfig('site_url'); - $name = md5('orcode' . date('Ymd')) . '.png'; + $name = 'orcode'.$data['id'] .md5(date('Ymd')) . '.png'; $attachmentRepository = app()->make(AttachmentRepository::class); $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]); @@ -653,12 +653,7 @@ class Common extends BaseController $imageInfo = null; } if (!$imageInfo) { - $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>[ - 'r' => 255, - 'g' => 221, - 'b' => 167, - 'a' => 0, - ]]); + $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>1]); if (is_string($imageInfo)) throw new ValidateException('二维码生成失败'); $imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl); diff --git a/app/controller/api/Demo.php b/app/controller/api/Demo.php index cad9fbe9..019ae041 100644 --- a/app/controller/api/Demo.php +++ b/app/controller/api/Demo.php @@ -19,7 +19,8 @@ use think\facade\Db; use crmeb\services\UploadService; use Exception; use ZipArchive; - +use think\facade\Queue; +use crmeb\jobs\ProductCopyJob; /** * Class Auth * @package app\controller\api @@ -29,205 +30,18 @@ use ZipArchive; class Demo extends BaseController { public function index() - { - $data=[ + { + return app('json')->success('修改成功'); + //[31,32,118,39,167,236,237,238,239] + // return app('json')->success('修改成功');>whereIn('mer_id',[110,116,149,227,226,35,117,148,156,104,137,151,136,183,140,229,79,133,235])-> - 6923644264192, - 6923644210151, - 6921665735042, - 6921665731693, - 6921665731679, - 6921665730825, - 6921665707940, - 6921665701054, - 6920208995349, - 6920208986163, - 6920208960866, - 6920208960064, - 6920208924394, - 6920208924035, - 6920208924011, - 6919188019961, - 6919188019961, - 6908791503943, - 6908791006024, - 6907992507385, - ]; - $mer_id=167; - foreach ($data as $item) { - $store_product_attr_value=Db::name('store_product_attr_value')->alias('a') - ->join('store_product b','a.product_id=b.product_id and b.product_type=98') - ->where('a.bar_code',$item)->value('a.product_id'); - if($store_product_attr_value){ - $find=Db::name('store_product_attr_value')->alias('a') - ->join('store_product b','a.product_id=b.product_id and b.product_type=0 and b.mer_id='.$mer_id) - ->where('a.bar_code',$item)->field('a.product_id,b.cate_id')->find(); - if($find){ - $cloud_product=Db::name('cloud_product')->where('product_id',$find['product_id'])->where('mer_id',$mer_id)->value('product_id'); - if(!$cloud_product){ - $source_mer_id = Db::name('store_product')->where('product_id', $store_product_attr_value)->value('mer_id'); - $datas = [ - 'product_id' => $find['product_id'], - 'cate_id' => $find['cate_id'], - 'mer_id' => $mer_id, - 'source_mer_id' => $source_mer_id, - 'street_code' => 510521107, - 'type_id' => 17, - 'category_id' => 2566, - 'weight' => 1, - 'status' => 1, - 'create_time' => date('Y-m-d H:i:s'), - 'mer_labels' =>'', - ]; - Db::name('cloud_product')->insert($datas); - } - } - } - } - halt(1); - $mer_id = 104; - $file = request()->file('file'); - $zip_name = explode('.', $file->getOriginalName())[0]; - // 上传到本地服务器 - $savename = \think\facade\Filesystem::putFile('zippic', $file); - $dir = date('Y-m-d_H-i-s') . '_' . $mer_id; - $path = public_path('uploads/pic').$dir; - try { - $zip = new ZipArchive; - $filePath = public_path('uploads') . $savename; - $zip->open($filePath); - for ($i = 0; $i < $zip->numFiles; $i++) { - $statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW); - $filename = $this->transcoding($statInfo['name']); - $mkdFile = explode('/',$filename); - if ($statInfo['crc'] == 0) { - // 新建目录 - if (!file_exists($path . '/' . $filename)) { - mkdir($path . '/' . $filename, 0777, true); - } - } else { - // 拷贝文件 - if(count($mkdFile)==3){ - if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) { - mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true); - } - copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename); - } - } - } - $zip->close(); - } catch (\Exception $e) { - throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine()); - } + $arr=Db::name('store_product')->whereIn('mer_id',[31,32,118,39,167,236,237,238,239])->where('is_show',1)->where('stock',0)->field('product_id')->select(); + foreach($arr as $item){ - $directory = $path.'/'.$zip_name; - $files = scandir($directory); - $dir = 'def/' . date('Y-m-d'); - $upload = UploadService::create(); - /**循环目录 */ - foreach ($files as $file) { - if ($file === '.' || $file === '..' || $file === '__MACOSX') { - continue; - } - if (!is_dir($directory . '/' . $file)) { - continue; - } - $files_two = scandir($directory . '/' . $file); + Queue::push(ProductCopyJob::class, ['product_id' => $item['product_id']]);//短信通知 - $image_extensions = array('jpg', 'jpeg', 'png'); - $image = ''; - $slider_image = []; - $details = []; - $sku_arr = []; - /**清洗图片 */ - foreach ($files_two as $file_two) { - if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') { - continue; - } - $arr = explode('.', $file_two); - if (in_array($arr[1], $image_extensions)) { - /**首图 */ - $images[] = $file_two; - if ($image == '' && is_numeric($arr[0])) { - $image = $directory . '/' . $file . '/' . $file_two; - continue; - } - /**轮播图 */ - if (is_numeric($arr[0]) && count($slider_image) < 4) { - $slider_image[] = $directory . '/' . $file . '/' . $file_two; - continue; - } - /**详情图 */ - if (is_numeric($arr[0])) { - $details[] = $directory . '/' .$file.'/'. $file_two; - continue; - } - /**sku图 */ - $sku = explode('==', $arr[0]); - if ($sku) { - $sku = implode(',', $sku); - $sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two; - } - } - } - $where = ['mer_id' => $mer_id, 'is_del' => 0]; - $update = []; - $update_content['title'] = ''; - $update_content['image'] = []; - $update_content['type'] = 1; - $find = Db::name('store_product')->where($where)->where('store_name', $file)->find(); - if ($find) { - try { - /**更新商品图片 */ - $image = $upload->to($dir)->stream(file_get_contents($image)); - $update['image'] = $image->filePath; - foreach ($slider_image as $k => $v) { - $oss = $upload->to($dir)->stream(file_get_contents($v)); - $update['slider_image'][] = $oss->filePath; - } - if (isset($update['slider_image'])) { - $update['slider_image'] = implode(',', $update['slider_image']); - } - Db::name('store_product')->where('product_id', $find['product_id'])->update($update); - /**更新规格图片 */ - foreach ($sku_arr as $k => $v) { - // $sku = explode(',', $k); - // if(count($sku)==2){ - // $sku_name=$sku[0]; - // }else{ - // continue; - // } - $store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find(); - if ($store_product_attr_value) { - $oss = $upload->to($dir)->stream(file_get_contents($v)); - Db::name('store_product_attr_value') - ->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k]) - ->update(['image' => $oss->filePath]); - } - } - /**更新详情图片 */ - $store_product_content = Db::name('store_product_content')->where(['product_id' => $find['product_id']])->find(); - foreach ($details as $k => $v) { - $oss = $upload->to($dir)->stream(file_get_contents($v)); - $update_content['image'][] = $oss->filePath; - } - if ($store_product_content) { - if (isset($update_content['image']) && !empty($update_content['image'])) { - Db::name('store_product_content') - ->where(['product_id' => $find['product_id']]) - ->update(['content' => json_encode($update_content)]); - } - } else { - $update_content['product_id'] = $find['product_id']; - Db::name('store_product_content') - ->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]); - } - } catch (Exception $e) { - halt($e->getMessage(), $e->getLine()); - } - } } - halt(1); + } public function transcoding($fileName) diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index bbc0146f..6a0090bf 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -94,7 +94,7 @@ class CloudWarehouse extends BaseController if ($value['mer_labels'] == ',5,') { $list[$k]['mer_labels_name'] = '五日达'; } else { - $list[$k]['mer_labels_name'] = '次日达'; + $list[$k]['mer_labels_name'] = '同城'; } } } diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index b584233f..85dea752 100644 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -541,7 +541,8 @@ class User extends BaseController */ public function qrcode(){ $common= app()->make(Common::class); - $data=$common->Qrcode(['code'=>'shop_'.$this->user->uid,'id'=>$this->user->uid]); + $siteUrl = systemConfig('site_url'); + $data=$common->Qrcode(['code'=>$siteUrl.'download/index.html?code=shop_'.$this->user->uid,'id'=>$this->user->uid]); return app('json')->success(['url'=>$data]); } } diff --git a/app/controller/merchant/store/product/Product.php b/app/controller/merchant/store/product/Product.php index e810819a..db78e094 100644 --- a/app/controller/merchant/store/product/Product.php +++ b/app/controller/merchant/store/product/Product.php @@ -468,7 +468,7 @@ class Product extends BaseController if ($value['mer_labels'] == ',5,') { $select[$k]['mer_labels_name'] = '五日达'; } else { - $select[$k]['mer_labels_name'] = '次日达'; + $select[$k]['mer_labels_name'] = '同城'; } } } diff --git a/app/listener/paySuccess.php b/app/listener/paySuccess.php index 2a856508..e80e9cf7 100644 --- a/app/listener/paySuccess.php +++ b/app/listener/paySuccess.php @@ -37,8 +37,9 @@ class paySuccess $orderList = $event['groupOrder']['orderList']; $storeConsumptionUserDao = new StoreConsumptionUserDao(); $storeConsumptionUserDao->check($event['groupOrder']['uid'], $event['groupOrder']['group_order_id']); +// $storeConsumptionUserDao->reduce($event['groupOrder']['consumption_id'], $event['groupOrder']['consumption_money']); foreach ($orderList as $k => $order) { - // + // $StoreProcessing->AutomaticallyCreateOrders($order); $this->recordOrderAddr($order); } diff --git a/config/cache.php b/config/cache.php index 15796fa0..620d58b3 100644 --- a/config/cache.php +++ b/config/cache.php @@ -16,7 +16,7 @@ return [ // 默认缓存驱动 - 'default' => env('INSTALLED', false) ? env('cache.driver', 'redis') : 'file', + 'default' => 'redis', // 缓存连接方式配置 'stores' => [ diff --git a/config/swoole.php b/config/swoole.php deleted file mode 100644 index 1f830cfd..00000000 --- a/config/swoole.php +++ /dev/null @@ -1,116 +0,0 @@ - -// +---------------------------------------------------------------------- - - -use app\webscoket\Manager; -use Swoole\Table; -use think\swoole\websocket\socketio\Parser; - -return [ - 'server' => [ - 'host' => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址 - 'port' => env('SWOOLE_PORT', 8324), // 监听端口 - 'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS - 'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP - 'options' => [ - 'pid_file' => runtime_path() . 'swoole.pid', - 'log_file' => runtime_path() . 'swoole.log', - 'daemonize' => false, - // Normally this value should be 1~4 times larger according to your cpu cores. - 'reactor_num' => swoole_cpu_num(), - 'worker_num' => swoole_cpu_num(), - 'task_worker_num' => swoole_cpu_num(), - 'task_enable_coroutine' => false, - 'task_max_request' => 2000, - 'enable_static_handler' => true, - 'document_root' => root_path('public'), - 'package_max_length' => 100 * 1024 * 1024, - 'buffer_output_size' => 10 * 1024 * 1024, - 'socket_buffer_size' => 128 * 1024 * 1024, - 'max_request' => 3000, - 'send_yield' => true, - 'reload_async' => true, - ], - ], - 'websocket' => [ - 'enable' => true, - 'handler' => Manager::class, - 'parser' => Parser::class, - 'ping_interval' => 25000, //1000 = 1秒 - 'ping_timeout' => 60000, //1000 = 1秒 - 'room' => [ - 'type' => 'table', - 'table' => [ - 'room_rows' => 4096, - 'room_size' => 2048, - 'client_rows' => 8192, - 'client_size' => 2048, - ], - 'redis' => [ - - ], - ], - 'listen' => [], - 'subscribe' => [], - ], - 'rpc' => [ - 'server' => [ - 'enable' => false, - 'port' => 9000, - 'services' => [ - ], - ], - 'client' => [ - ], - ], - 'hot_update' => [ - 'enable' => env('APP_DEBUG', false), - 'name' => ['*.php'], - 'include' => [app_path(),root_path().'crmeb'], - 'exclude' => [], - ], - //连接池 - 'pool' => [ - 'db' => [ - 'enable' => true, - 'max_active' => 3, - 'max_wait_time' => 5, - ], - 'cache' => [ - 'enable' => true, - 'max_active' => 3, - 'max_wait_time' => 5, - ], - ], - 'coroutine' => [ - 'enable' => false, - 'flags' => SWOOLE_HOOK_ALL, - ], - 'tables' => [ - 'user' => [ - 'size' => 204800, - 'columns' => [ - ['name' => 'fd', 'type' => Table::TYPE_INT], - ['name' => 'type', 'type' => Table::TYPE_INT], - ['name' => 'uid', 'type' => Table::TYPE_INT] - ] - ] - ], - //每个worker里需要预加载以共用的实例 - 'concretes' => [], - //重置器 - 'resetters' => [], - //每次请求前需要清空的实例 - 'instances' => [], - //每次请求前需要重新执行的服务 - 'services' => [], - 'locks' => ['group_buying'], -]; diff --git a/crmeb/jobs/ProductCopyJob.php b/crmeb/jobs/ProductCopyJob.php new file mode 100644 index 00000000..111d9fb7 --- /dev/null +++ b/crmeb/jobs/ProductCopyJob.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- + + +namespace crmeb\jobs; + + +use crmeb\interfaces\JobInterface; +use app\controller\admin\store\StoreProduct; +use think\facade\Db; + +/** + * 本地跑远程线程专门使用 + */ +class ProductCopyJob implements JobInterface +{ + + public function fire($job, $data) + { + // $arrs= Db::name('store_product')->where('old_product_id',$data['product_id'])->select(); + // foreach($arrs as $it){ + // $res= Db::name('store_product')->where('product_id',$it['product_id'])->update(['is_del'=>1,'is_show'=>0,'is_used'=>0,'status'=>-2]); + // if($res){ + // Db::name('cloud_product')->where('product_id',$it['product_id'])->delete(); + + // } + // } + // $make = app()->make(StoreProduct::class); + // $make->copy($data['product_id'],$data['mer_id'],$data['street_code'],$data['type_id'],$data['category_id']); + $job->delete(); + } + + + public function failed($data) + { + // TODO: Implement failed() method. + } +} diff --git a/crmeb/services/QrcodeService.php b/crmeb/services/QrcodeService.php index 1a90396c..a8f22eb4 100644 --- a/crmeb/services/QrcodeService.php +++ b/crmeb/services/QrcodeService.php @@ -41,10 +41,22 @@ class QrcodeService if (!$siteUrl) return '请前往后台设置->系统设置->网站域名 填写您的域名格式为:http://域名'; $info = []; $outfile = Config::get('qrcode.cache_dir'); - $code = new QrCode($url); + $code = new QrCode(); if(isset($data['code'])){ - $code->setForegroundColor($data['code']); + $code->setForegroundColor([ + 'r' => 248, + 'g' => 150, + 'b' => 46, + 'a' => 0, + ]); + $code->setBackgroundColor([ + 'r' => 255, + 'g' => 246, + 'b' => 235, + 'a' => 0, + ]); } + $code->setText($url); if ($uploadType === 1) { if (!is_dir('./public/' . $outfile)) mkdir('./public/' . $outfile, 0777, true);