diff --git a/app/controller/api/user/User.php b/app/controller/api/user/User.php index 85dea752..81ad03aa 100755 --- a/app/controller/api/user/User.php +++ b/app/controller/api/user/User.php @@ -14,7 +14,11 @@ namespace app\controller\api\user; +use app\common\dao\store\order\StoreOrderDao; +use app\common\model\store\order\StoreOrderOther; +use app\common\model\system\merchant\Merchant; use app\common\repositories\store\IntegralRepository; +use app\common\repositories\store\order\PresellOrderRepository; use app\common\repositories\store\service\StoreServiceRepository; use app\common\repositories\system\CacheRepository; use app\common\repositories\user\MemberinterestsRepository; @@ -31,6 +35,7 @@ use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use app\controller\api\Common; +use app\common\model\user\User as UserModel; class User extends BaseController { @@ -545,4 +550,39 @@ class User extends BaseController $data=$common->Qrcode(['code'=>$siteUrl.'download/index.html?code=shop_'.$this->user->uid,'id'=>$this->user->uid]); return app('json')->success(['url'=>$data]); } + + /** + * 邀请的商户记录 + * @return mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function merchantRecord() + { + [$page, $limit] = $this->getPage(); + $userIds = UserModel::where('spread_uid', $this->user->uid)->column('uid'); + $query = Merchant::whereIn('uid', $userIds) + ->where('status', 1) + ->where('is_del', 0) + ->where('mer_state', 1); + $count = $query->count(); + $result = $query->page($page, $limit) + ->field('mer_id,mer_name,uid,real_name') + ->select()->toArray(); + $dao = new StoreOrderDao(); + /** @var PresellOrderRepository $preSellDao */ + $preSellRepo = app()->make(PresellOrderRepository::class); + foreach ($result as &$item) { + $saleOrderQuery = $dao->search(['mer_id' => $item['mer_id']])->whereIn('StoreOrder.status', [0, 1, 2, 3, 9, 10])->where('paid', 1); + $saleOrderIds = $saleOrderQuery->column('order_id'); + $saleAmount1 = $saleOrderQuery->sum('StoreOrder.pay_price'); + $saleAmount2 = $preSellRepo->search(['paid' => 1, 'order_ids' => $saleOrderIds])->sum('pay_price'); + $item['sale_amount'] = bcadd($saleAmount1, $saleAmount2, 2); + $item['buy_amount'] = StoreOrderOther::where('uid', $item['uid'])->whereIn('status', [0, 1, 2, 3, 9, 10])->where('paid', 1)->sum('pay_price'); + $item['buy_amount'] = bcadd($item['buy_amount'], 0, 2); + } + return app('json')->success(['count' => $count, 'list' => $result]); + } + } diff --git a/route/api.php b/route/api.php index 6f106971..f0471372 100755 --- a/route/api.php +++ b/route/api.php @@ -46,8 +46,9 @@ Route::group('api/', function () { Route::post('articleCatch', 'api.Upload/article'); //强制登录 Route::group(function () { - + Route::any('qrcode', 'api.user.User/qrcode'); + Route::get('merchantRecord', 'api.user.User/merchantRecord'); Route::post('merchant_license_identify', 'api.Common/merchant_license_identify');//营业执照识别