diff --git a/app/Commons/LanzuRequest.php b/app/Commons/LanzuRequest.php deleted file mode 100644 index 38e4ce0..0000000 --- a/app/Commons/LanzuRequest.php +++ /dev/null @@ -1,61 +0,0 @@ -storeParsedData(function () { - // $request = $this->getRequest(); - // if (is_array($request->getParsedBody())) { - // $data = $request->getParsedBody(); - // } else { - // $data = []; - // } - - // return array_merge($data, $request->getQueryParams()); - // }); - // } - - protected function storeParsedData(callable $callback) - { - if (! Context::has($this->contextkeys['parsedData'])) { - return Context::set($this->contextkeys['parsedData'], call($callback)); - } - - // var_dump(Context::get($this->contextkeys['parsedData'])); - - $preDatas = Context::get($this->contextkeys['parsedData']); - - if(isset($preDatas['market_id'])){ - if($preDatas['market_id']==-1){ - $preDatas['market_id'] = 0; - unset($preDatas['sign']); - $sign = $this->signature($preDatas); - $preDatas['sign'] = $sign; - Context::set($this->contextkeys['parsedData'],$preDatas); - } - } - - return Context::get($this->contextkeys['parsedData']); - } - - private function signature($params) - { - ksort($params); - - $http_query = []; - foreach ($params as $key => $value) { - $http_query[] = $key.'='.$value; - } - - return sha1(md5(implode('&', $http_query)).config('auth.api.sign.secret_key')); - } -} diff --git a/app/Controller/v3/WithdrawController.php b/app/Controller/v3/WithdrawController.php index 4ccae31..9a6f99f 100644 --- a/app/Controller/v3/WithdrawController.php +++ b/app/Controller/v3/WithdrawController.php @@ -157,7 +157,7 @@ class WithdrawController extends BaseController $withdraw->apply_cash = $money; $withdraw->save(); - // 扣除余额 + // 先扣除余额 $balance->balance = bcsub($balance->balance, $money, 2); $balance->save(); @@ -171,7 +171,17 @@ class WithdrawController extends BaseController $withdraw->name, '商户提现打款' ); + // 更新打款金额,审核时间等 + $withdraw->check_time = time(); + $withdraw->real_cash = $money; + $withdraw->state = 2; + $withdraw->save(); + + // 打款成功,写流水 + if ($res === true) { + $this->financialService->storeWithdrawByWx($store->user_id, 0, $withdraw->real_cash); + } } Db::commit(); diff --git a/app/Middleware/Auth/ApiMiddleware.php b/app/Middleware/Auth/ApiMiddleware.php index 826203c..271d20c 100644 --- a/app/Middleware/Auth/ApiMiddleware.php +++ b/app/Middleware/Auth/ApiMiddleware.php @@ -85,10 +85,23 @@ class ApiMiddleware implements MiddlewareInterface if ($exists) { $hashIds = ApplicationContext::getContainer()->get(Hashids::class); $user = $hashIds->decode($userToken); - $this->request->user = User::query()->find($user[0]); + $userModel = User::query()->find($user[0]); + $userModel->userToken = $userToken; + $this->request->user = $userModel; } } + // 处理全局默认值 + $request = \Hyperf\Utils\Context::override(ServerRequestInterface::class, function (ServerRequestInterface $request) + { + $preDatas = $request->getParsedBody(); + if (isset($preDatas['market_id']) && $preDatas['market_id'] == -1) { + $preDatas['market_id'] = 1; + } + + return $request->withParsedBody($preDatas); + }); + return $handler->handle($request); } diff --git a/app/Middleware/CorsMiddleware.php b/app/Middleware/CorsMiddleware.php index 45479a6..71c5530 100644 --- a/app/Middleware/CorsMiddleware.php +++ b/app/Middleware/CorsMiddleware.php @@ -29,35 +29,35 @@ class CorsMiddleware implements MiddlewareInterface return $response; } - $request = \Hyperf\Utils\Context::override(ServerRequestInterface::class, function (ServerRequestInterface $request) - { - $preDatas = $request->getParsedBody(); - if(isset($preDatas['market_id'])){ - if($preDatas['market_id']==-1){ - $preDatas['market_id'] = 0; - - if (env('APP_ENV') == 'prod') { - unset($preDatas['sign']); - $sign = $this->signature($preDatas); - $preDatas['sign'] = $sign; - } - } - } - return $request->withParsedBody($preDatas); - }); + // $request = \Hyperf\Utils\Context::override(ServerRequestInterface::class, function (ServerRequestInterface $request) + // { + // $preDatas = $request->getParsedBody(); + // if(isset($preDatas['market_id'])){ + // if($preDatas['market_id']==-1){ + // $preDatas['market_id'] = 0; + // + // if (env('APP_ENV') == 'prod') { + // unset($preDatas['sign']); + // $sign = $this->signature($preDatas); + // $preDatas['sign'] = $sign; + // } + // } + // } + // return $request->withParsedBody($preDatas); + // }); return $handler->handle($request); } - private function signature($params) - { - ksort($params); - - $http_query = []; - foreach ($params as $key => $value) { - $http_query[] = $key.'='.$value; - } - - return sha1(md5(implode('&', $http_query)).config('auth.api.sign.secret_key')); - } + // private function signature($params) + // { + // ksort($params); + // + // $http_query = []; + // foreach ($params as $key => $value) { + // $http_query[] = $key.'='.$value; + // } + // + // return sha1(md5(implode('&', $http_query)).config('auth.api.sign.secret_key')); + // } } \ No newline at end of file diff --git a/app/Model/v3/FinancialRecord.php b/app/Model/v3/FinancialRecord.php index e214652..3a24229 100644 --- a/app/Model/v3/FinancialRecord.php +++ b/app/Model/v3/FinancialRecord.php @@ -47,6 +47,7 @@ class FinancialRecord extends Model * 订单 * SOURCE_TYPE_ORDER / 1 */ + const SOURCE_TYPE_NONE = 0; const SOURCE_TYPE_ORDER = 1; /** @@ -60,9 +61,18 @@ class FinancialRecord extends Model const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入 const MONEY_TYPE_STORE_OFL_ORDER_COMP = 7; // 商户线下订单完成收入 const MONEY_TYPE_USER_OL_ORDER_REFUND = 8; // 用户线上订单退款 + const MONEY_TYPE_MM_PLAT_NEW_USER = 9; // 市场经理发展新用户 + const MONEY_TYPE_MM_PLAT_NEW_STORE = 10; // 市场经理发展新商户 + const MONEY_TYPE_MP_PLAT_NEW_USER = 11; // 服务商发展新用户 + const MONEY_TYPE_MP_PLAT_NEW_STORE = 12; // 服务商发展新商户 + const MONEY_TYPE_MP_OL_ORDER = 13; // 服务商线上订单分账(线上订单完成) const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单 const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单 + const MONEY_TYPE_MP_WITHDRAW = 102; // 服务商提现类型 + const MONEY_TYPE_MM_WITHDRAW = 103; // 市场经理提现类型 + const MONEY_TYPE_CS_WITHDRAW = 104; // 社区提现类型 + const MONEY_TYPE_STORE_WITHDRAW = 105; // 商户提现类型 /** * 状态 diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 4eea067..9e59936 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -99,4 +99,5 @@ class GoodsActivity extends Model { return $this->morphMany(ShoppingCart::class, 'goods'); } + } \ No newline at end of file diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index f61a37c..ac57d12 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -2,17 +2,24 @@ namespace App\Service\v3\Implementations; -use App\Model\ShopCar; use App\Model\v3\Coupon; use App\Model\v3\CouponRec; use App\Service\v3\Interfaces\CouponRecServiceInterface; +use App\Service\v3\Interfaces\ShopCartServiceInterface; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; +use Hyperf\Di\Annotation\Inject; class CouponRecService implements CouponRecServiceInterface { + /** + * @Inject + * @var ShopCartServiceInterface + */ + protected $shopCartService; + public function do() { // TODO: Implement do() method. @@ -79,6 +86,11 @@ class CouponRecService implements CouponRecServiceInterface /** * 用户优惠券列表 + * @param $userId + * @param $type + * @param int $page + * @param int $pagesize + * @return array */ public function getListByUser($userId,$type,$page = 1,$pagesize = 5) { @@ -143,12 +155,22 @@ class CouponRecService implements CouponRecServiceInterface * 2、筛选出其中当日使用过的优惠券 * 3、筛选出其中活动商品不可用的优惠券(订单中有活动商品且活动商品不可使用优惠券) * 4、筛选出其中活动商品可用但商品的活动类型不符合优惠券活动使用类型的要求(订单中有活动商品可以用优惠券,但是活动类型type和优惠券中的available活动类型不可用) - * @param $cartIds * @param $userId * @param $marketId */ - public function allForOnlineOrderAvailable($cartIds, $userId, $marketId) + public function allForOnlineOrderAvailable($userId, $marketId) { + // 获取购物车数据 + $carts = $this->shopCartService->allForUser($userId, $marketId); + $totalAmount = $carts['total']; + + // 获取用户可用优惠券(1) + $coupons = CouponRec::query() + ->join('lanzu_coupon as coupon', 'coupon.id', '=', '') + ->where(['user_id' => $userId]) + ->where('number_remain', '>', 0) + ->whereIn('status', [0,1]) + ->get(); } diff --git a/app/Service/v3/Implementations/FinancialRecordService.php b/app/Service/v3/Implementations/FinancialRecordService.php index 97fc31c..b09920d 100644 --- a/app/Service/v3/Implementations/FinancialRecordService.php +++ b/app/Service/v3/Implementations/FinancialRecordService.php @@ -333,4 +333,22 @@ class FinancialRecordService implements FinancialRecordServiceInterface return bcadd($sumAmount, '0', 2); } + + /** + * @inheritDoc + */ + public function storeWithdrawByWx( + $user_id, + $source_id, + $money, + $user_type = UserType::STORE, + $source_type = FinancialRecord::SOURCE_TYPE_NONE, + $money_type = FinancialRecord::MONEY_TYPE_STORE_WITHDRAW, + $desc = '商户提现', + $comment = '商户提现打款' + ) + { + $this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment); + + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 798497d..7f1cf60 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -91,10 +91,8 @@ class GoodsActivityService implements GoodsActivityServiceInterface $expireTime = 0; if ($goods->time_limit_days >= 1) { $expireTime += strtotime(date('Y-m-d 23:59:59')) - time(); - var_dump('ex1', $expireTime); } $expireTime += ($goods->time_limit_days-1) * 86400; - var_dump('ex2', $expireTime); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); @@ -112,19 +110,16 @@ class GoodsActivityService implements GoodsActivityServiceInterface $goods = GoodsActivity::query() ->where('id', $goodsId) ->first(); - var_dump('$goods', $goods, $goodsId); if (empty($goods)) { return true; } $ssdbKey = SsdbKeys::ACTIVITY_GOODS_BUY_RECORD.$userId.'_'.$goods->type.'_'.$goodsId; - var_dump('ssdbkey', $ssdbKey); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); if (!$ssdb->exec('exists', $ssdbKey)) { } else { $res = $ssdb->exec('incr', $ssdbKey, -1*$num); - var_dump('res', $res, -1*$num); } } diff --git a/app/Service/v3/Implementations/OrderOfflineService.php b/app/Service/v3/Implementations/OrderOfflineService.php index 4fdc741..f0e76e5 100644 --- a/app/Service/v3/Implementations/OrderOfflineService.php +++ b/app/Service/v3/Implementations/OrderOfflineService.php @@ -2,6 +2,7 @@ namespace App\Service\v3\Implementations; +use App\Commons\Log; use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; use App\Constants\v3\OrderState; @@ -26,6 +27,12 @@ class OrderOfflineService implements OrderOfflineServiceInterface */ protected $paymentService; + /** + * @Inject + * @var Log + */ + protected $log; + public function do($storeId, $userId, $money, $plat ='') { try { @@ -62,8 +69,9 @@ class OrderOfflineService implements OrderOfflineServiceInterface // 店铺今天的订单数 $count = Order::query() - ->where(['store_id' => $storeId, 'type' => OrderType::OFFLINE]) - ->whereBetween('created_at', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]) + ->join('lanzu_order_main as main', 'main.id', '=', 'lanzu_order.order_main_id') + ->where(['lanzu_order.store_id' => $storeId, 'main.type' => OrderType::OFFLINE]) + ->whereBetween('lanzu_order.created_at', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]) ->count(); // 子订单数据 diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 7e421e5..cdc2e36 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -207,7 +207,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface 'name' => $goods->name, 'goods_unit' => $goods->goods_unit, 'cover_img' => $goods->cover_img, - 'spec' => $goods->spec, + 'spec' => json_encode($goods->spec), ]; } diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index 660d9dd..9caf6e1 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -44,7 +44,7 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface } } - $builder->select(['id', 'store_id', 'cover_img', 'name', 'spec', 'tags', 'original_price', 'price', 'inventory', 'sales as total_sales']); + $builder->select(['*'])->addSelect(['sales as total_sales']); $paginate = $builder->paginate($params['pagesize']); $goods = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods['data']]; @@ -55,7 +55,7 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface $builder = Store::query() ->with(['goods' => function($query) { return $query->limit(5) - ->select(['id', 'store_id', 'cover_img', 'name', 'spec', 'tags', 'original_price', 'price', 'inventory', 'sales as total_sales']); + ->select(['*'])->addSelect(['sales as total_sales']); }]) ->where(['market_id' => $params['market_id']]); diff --git a/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php b/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php index 6958fb2..c0c5932 100644 --- a/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php +++ b/app/Service/v3/Interfaces/FinancialRecordServiceInterface.php @@ -3,7 +3,7 @@ namespace App\Service\v3\Interfaces; use App\Constants\v3\UserType; -use App\Model\FinancialRecord; +use App\Model\v3\FinancialRecord; interface FinancialRecordServiceInterface { @@ -263,4 +263,27 @@ interface FinancialRecordServiceInterface $money_type = [] ); + /** + * 商户微信提现流水 + * @param $user_id + * @param $source_id + * @param $money + * @param int $user_type + * @param int $source_type + * @param int $money_type + * @param string $desc + * @param string $comment + * @return mixed + */ + public function storeWithdrawByWx( + $user_id, + $source_id, + $money, + $user_type = UserType::STORE, + $source_type = FinancialRecord::SOURCE_TYPE_NONE, + $money_type = FinancialRecord::MONEY_TYPE_STORE_WITHDRAW, + $desc='商户提现', + $comment='' + ); + } \ No newline at end of file