diff --git a/application/admin/controller/order/StoreOrder.php b/application/admin/controller/order/StoreOrder.php index d006ad6a..426aa4f9 100644 --- a/application/admin/controller/order/StoreOrder.php +++ b/application/admin/controller/order/StoreOrder.php @@ -1 +1 @@ -assign([ 'year'=>getMonth('y'), 'real_name'=>$this->request->get('real_name',''), 'orderCount'=>StoreOrderModel::orderCount(), ]); return $this->fetch(); } /** * 获取头部订单金额等信息 * return json * */ public function getBadge(){ $where = Util::postMore([ ['status',''], ['real_name',''], ['is_del',0], ['data',''], ['type',''], ['order',''] ]); return JsonService::successful(StoreOrderModel::getBadge($where)); } /** * 获取订单列表 * return json */ public function order_list(){ $where = Util::getMore([ ['status',''], ['real_name',$this->request->param('real_name','')], ['is_del',0], ['data',''], ['type',''], ['order',''], ['page',1], ['limit',20], ['excel',0] ]); return JsonService::successlayui(StoreOrderModel::OrderList($where)); } public function orderchart(){ $where = Util::getMore([ ['status',''], ['real_name',''], ['is_del',0], ['data',''], ['combination_id',''], ['export',0], ['order','id desc'] ],$this->request); $limitTimeList = [ 'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]), 'week'=>implode(' - ',[ date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)), date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) ]), 'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]), 'quarter'=>implode(' - ',[ date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01', date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y'))) ]), 'year'=>implode(' - ',[ date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day')) ]) ]; if($where['data'] == '') $where['data'] = $limitTimeList['today']; $orderCount = [ urlencode('未支付')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(0))->count(), urlencode('未发货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(1))->count(), urlencode('待收货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(2))->count(), urlencode('待评价')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(3))->count(), urlencode('交易完成')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(4))->count(), urlencode('退款中')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-1))->count(), urlencode('已退款')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-2))->count() ]; $model = StoreOrderModel::getOrderWhere($where,new StoreOrderModel())->field('sum(total_num) total_num,count(*) count,sum(total_price) total_price,sum(refund_price) refund_price,from_unixtime(add_time,\'%Y-%m-%d\') add_time') ->group('from_unixtime(add_time,\'%Y-%m-%d\')'); $orderPrice = $model->select()->toArray(); $orderDays = []; $orderCategory = [ ['name'=>'商品数','type'=>'line','data'=>[]], ['name'=>'订单数','type'=>'line','data'=>[]], ['name'=>'订单金额','type'=>'line','data'=>[]], ['name'=>'退款金额','type'=>'line','data'=>[]] ]; foreach ($orderPrice as $price){ $orderDays[] = $price['add_time']; $orderCategory[0]['data'][] = $price['total_num']; $orderCategory[1]['data'][] = $price['count']; $orderCategory[2]['data'][] = $price['total_price']; $orderCategory[3]['data'][] = $price['refund_price']; } $this->assign(StoreOrderModel::systemPage($where,$this->adminId)); $this->assign('price',StoreOrderModel::getOrderPrice($where)); $this->assign(compact('limitTimeList','where','orderCount','orderPrice','orderDays','orderCategory')); return $this->fetch(); } /** * 修改支付金额等 * @param $id * @return mixed|\think\response\Json|void */ public function edit($id) { if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); $f = array(); $f[] = Form::input('order_id','订单编号',$product->getData('order_id'))->disabled(1); $f[] = Form::number('total_price','商品总价',$product->getData('total_price'))->min(0); $f[] = Form::number('total_postage','原始邮费',$product->getData('total_postage'))->min(0); $f[] = Form::number('pay_price','实际支付金额',$product->getData('pay_price'))->min(0); $f[] = Form::number('pay_postage','实际支付邮费',$product->getData('pay_postage')); $f[] = Form::number('gain_integral','赠送积分',$product->getData('gain_integral')); // $f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]); $form = Form::make_post_form('修改订单',$f,Url::build('update',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /** 修改订单提交更新 * @param Request $request * @param $id */ public function update(Request $request, $id) { $data = Util::postMore([ 'order_id', 'total_price', 'total_postage', 'pay_price', 'pay_postage', 'gain_integral', ],$request); if($data['total_price'] <= 0) return Json::fail('请输入商品总价'); if($data['pay_price'] <= 0) return Json::fail('请输入实际支付金额'); $data['order_id'] = StoreOrderModel::changeOrderId($data['order_id']); StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_edit',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'order_edit','修改商品总价为:'.$data['total_price'].' 实际支付金额'.$data['pay_price']); return Json::successful('修改成功!'); } /** * 送货 * @param $id * send */ public function delivery($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1 && $product['status'] == 0) { $f = array(); $f[] = Form::input('delivery_name','送货人姓名')->required('送货人姓名不能为空','required:true;'); $f[] = Form::input('delivery_id','送货人电话')->required('请输入正确电话号码','telephone'); $form = Form::make_post_form('修改订单',$f,Url::build('updateDelivery',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } else return Json::fail('数据不存在!'); } public function updateDelivery(Request $request, $id){ $data = Util::postMore([ 'delivery_name', 'delivery_id', ],$request); $data['delivery_type'] = 'send'; if(!$data['delivery_name']) return Json::fail('请输入送货人姓名'); if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码'); else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码'); $data['status'] = 1; StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_delivery',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']); return Json::successful('修改成功!'); } /** * 发货 * @param $id * express */ public function deliver_goods($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1 && $product['status'] == 0){ $f = array(); $f[] = Form::select('delivery_name','快递公司')->setOptions(function(){ $list = db('express')->where('is_show',1)->order('sort DESC')->column('id,name'); $menus = []; foreach ($list as $k=>$v){ $menus[] = ['value'=>$v,'label'=>$v]; } return $menus; })->filterable(1); $f[] = Form::input('delivery_id','快递单号')->number(1); $form = Form::make_post_form('修改订单',$f,Url::build('updateDeliveryGoods',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } else return Json::fail('数据不存在!'); } /**发货保存 * @param Request $request * @param $id */ public function updateDeliveryGoods(Request $request, $id){ $data = Util::postMore([ 'delivery_name', 'delivery_id', ],$request); $data['delivery_type'] = 'express'; if(!$data['delivery_name']) return Json::fail('请选择快递公司'); if(!$data['delivery_id']) return Json::fail('请输入快递单号'); $data['status'] = 1; StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_delivery_goods',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'delivery_goods','已发货 快递公司:'.$data['delivery_name'].' 快递单号:'.$data['delivery_id']); return Json::successful('修改成功!'); } /** * 修改状态为已收货 * @param $id * @return \think\response\Json|void */ public function take_delivery($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['status'] == 2) return Json::fail('不能重复收货!'); if($product['paid'] == 1 && $product['status'] == 1) $data['status'] = 2; else if($product['pay_type'] == 'offline') $data['status'] = 2; else return Json::fail('请先发货或者送货!'); if(!StoreOrderModel::edit($data,$id)) return Json::fail(StoreOrderModel::getErrorInfo('收货失败,请稍候再试!')); else{ try{ HookService::listen('store_product_order_take_delivery',$data,$id,false,StoreProductBehavior::class); }catch (Exception $e){ return Json::fail($e->getMessage()); } StoreOrderStatus::setStatus($id,'take_delivery','已收货'); return Json::successful('收货成功!'); } } /** * 修改退款状态 * @param $id * @return \think\response\Json|void */ public function refund_y($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1){ $f = array(); $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); $f[] = Form::number('refund_price','退款金额',$product->getData('pay_price'))->precision(2)->min(0.01); $f[] = Form::radio('type','状态',1)->options([['label'=>'直接退款','value'=>1],['label'=>'退款后,返回原状态','value'=>2]]); $form = Form::make_post_form('退款处理',$f,Url::build('updateRefundY',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } else return Json::fail('数据不存在!'); } /**退款处理 * @param Request $request * @param $id */ public function updateRefundY(Request $request, $id){ $data = Util::postMore([ 'refund_price', ['type',1], ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['pay_price'] == $product['refund_price']) return Json::fail('已退完支付金额!不能再退款了'); if(!$data['refund_price']) return Json::fail('请输入退款金额'); $refund_price = $data['refund_price']; $data['refund_price'] = bcadd($data['refund_price'],$product['refund_price'],2); $bj = bccomp((float)$product['pay_price'],(float)$data['refund_price'],2); if($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额'); if($data['type'] == 1){ $data['refund_status'] = 2; }else if($data['type'] == 2){ $data['refund_status'] = 0; } $type = $data['type']; unset($data['type']); $refund_data['pay_price'] = $product['pay_price']; $refund_data['refund_price'] = $refund_price; if($product['pay_type'] == 'weixin'){ if($product['is_channel']){ try{ HookService::listen('routine_pay_order_refund',$product['order_id'],$refund_data,true,PaymentBehavior::class); }catch(\Exception $e){ return Json::fail($e->getMessage()); } }else{ try{ HookService::listen('wechat_pay_order_refund',$product['order_id'],$refund_data,true,PaymentBehavior::class); }catch(\Exception $e){ return Json::fail($e->getMessage()); } } }else if($product['pay_type'] == 'yue'){ ModelBasic::beginTrans(); $res1 = User::bcInc($product['uid'],'now_money',$refund_price,'uid'); $res2 = $res2 = UserBill::income('商品退款',$product['uid'],'now_money','pay_product_refund',$refund_price,$product['id'],$product['pay_price'],'订单退款到余额'.floatval($refund_price).'元'); try{ HookService::listen('store_order_yue_refund',$product,$refund_data,false,StoreProductBehavior::class); }catch (\Exception $e){ ModelBasic::rollbackTrans(); return Json::fail($e->getMessage()); } $res = $res1 && $res2; ModelBasic::checkTrans($res); if(!$res) return Json::fail('余额退款失败!'); } $resEdit = StoreOrderModel::edit($data,$id); if($resEdit){ $data['type'] = $type; if($data['type'] == 1) StorePink::setRefundPink($id); HookService::afterListen('store_product_order_refund_y',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元'); return Json::successful('修改成功!'); }else{ StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元失败'); return Json::successful('修改失败!'); } } public function order_info($oid = '') { if(!$oid || !($orderInfo = StoreOrderModel::get($oid))) return $this->failed('订单不存在!'); $userInfo = User::getUserInfo($orderInfo['uid']); if($userInfo['spread_uid']){ $spread = User::where('uid',$userInfo['spread_uid'])->value('nickname'); }else{ $spread =''; } $this->assign(compact('orderInfo','userInfo','spread')); return $this->fetch(); } public function express($oid = '') { if(!$oid || !($order = StoreOrderModel::get($oid))) return $this->failed('订单不存在!'); if($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!'); $cacheName = $order['order_id'].$order['delivery_id']; $result = CacheService::get($cacheName,null); if($result === null || 1==1){ $result = Express::query($order['delivery_id']); if(is_array($result) && isset($result['result']) && isset($result['result']['deliverystatus']) && $result['result']['deliverystatus'] >= 3) $cacheTime = 0; else $cacheTime = 1800; CacheService::set($cacheName,$result,$cacheTime); } $this->assign([ 'order'=>$order, 'express'=>$result ]); return $this->fetch(); } /** * 修改配送信息 * @param $id * @return mixed|\think\response\Json|void */ public function distribution($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); $f = array(); $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); if($product['delivery_type'] == 'send'){ $f[] = Form::input('delivery_name','送货人姓名',$product->getData('delivery_name')); $f[] = Form::input('delivery_id','送货人电话',$product->getData('delivery_id')); }else if($product['delivery_type'] == 'express'){ $f[] = Form::select('delivery_name','快递公司',$product->getData('delivery_name'))->setOptions(function (){ $list = db('express')->where('is_show',1)->column('id,name'); $menus = []; foreach ($list as $k=>$v){ $menus[] = ['value'=>$v,'label'=>$v]; } return $menus; }); $f[] = Form::input('delivery_id','快递单号',$product->getData('delivery_id')); } $form = Form::make_post_form('配送信息',$f,Url::build('updateDistribution',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /**修改配送信息 * @param Request $request * @param $id */ public function updateDistribution(Request $request, $id){ $data = Util::postMore([ 'delivery_name', 'delivery_id', ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['delivery_type'] == 'send'){ if(!$data['delivery_name']) return Json::fail('请输入送货人姓名'); if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码'); else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码'); }else if($product['delivery_type'] == 'express'){ if(!$data['delivery_name']) return Json::fail('请选择快递公司'); if(!$data['delivery_id']) return Json::fail('请输入快递单号'); } StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_distribution',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'distribution','修改发货信息为'.$data['delivery_name'].'号'.$data['delivery_id']); return Json::successful('修改成功!'); } /** * 修改退款状态 * @param $id * @return mixed|\think\response\Json|void */ public function refund_n($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); $f[] = Form::input('refund_reason','退款原因')->type('textarea'); $form = Form::make_post_form('退款',$f,Url::build('updateRefundN',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /**不退款原因 * @param Request $request * @param $id */ public function updateRefundN(Request $request, $id){ $data = Util::postMore([ 'refund_reason', ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if(!$data['refund_reason']) return Json::fail('请输入退款原因'); $data['refund_status'] = 0; StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_refund_n',$data['refund_reason'],$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'refund_n','不退款原因:'.$data['refund_reason']); return Json::successful('修改成功!'); } /** * 立即支付 * @param $id */ public function offline($id){ $res = StoreOrderModel::updateOffline($id); if($res){ try{ HookService::listen('store_product_order_offline',$id,false,StoreProductBehavior::class); }catch (Exception $e){ return Json::fail($e->getMessage()); } StoreOrderStatus::setStatus($id,'offline','线下付款'); return Json::successful('修改成功!'); }else{ return Json::fail('修改失败!'); } } /** * 修改积分和金额 * @param $id * @return mixed|\think\response\Json|void */ public function integral_back($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1){ $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); $f[] = Form::number('back_integral','退积分')->min(0); $form = Form::make_post_form('退积分',$f,Url::build('updateIntegralBack',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); }else{ return Json::fail('参数错误!'); } return $this->fetch('public/form-builder'); } /** 退积分保存 * @param Request $request * @param $id */ public function updateIntegralBack(Request $request, $id){ $data = Util::postMore([ 'back_integral', ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($data['back_integral'] <= 0) return Json::fail('请输入积分'); if($product['use_integral'] == $product['back_integral']) return Json::fail('已退完积分!不能再积分了'); $back_integral = $data['back_integral']; $data['back_integral'] = bcadd($data['back_integral'],$product['back_integral'],2); $bj = bccomp((float)$product['use_integral'],(float)$data['back_integral'],2); if($bj < 0) return Json::fail('退积分大于支付积分,请修改退积分'); ModelBasic::beginTrans(); $res1 = User::bcInc($product['uid'],'integral',$back_integral,'uid'); $res2 = UserBill::income('商品退积分',$product['uid'],'integral','pay_product_integral_back',$back_integral,$product['id'],$product['pay_price'],'订单退积分'.floatval($back_integral).'积分到用户积分'); try{ HookService::listen('store_order_integral_back',$product,$back_integral,false,StoreProductBehavior::class); }catch (\Exception $e){ ModelBasic::rollbackTrans(); return Json::fail($e->getMessage()); } $res = $res1 && $res2; ModelBasic::checkTrans($res); if(!$res) return Json::fail('退积分失败!'); StoreOrderModel::edit($data,$id); StoreOrderStatus::setStatus($id,'integral_back','商品退积分:'.$data['back_integral']); return Json::successful('退积分成功!'); } public function remark(Request $request){ $data = Util::postMore(['id','remark'],$request); if(!$data['id']) return Json::fail('参数错误!'); if($data['remark'] == '') return Json::fail('请输入要备注的内容!'); $id = $data['id']; unset($data['id']); StoreOrderModel::edit($data,$id); return Json::successful('备注成功!'); } public function order_status($oid){ if(!$oid) return $this->failed('数据不存在'); $this->assign(StoreOrderStatus::systemPage($oid)); return $this->fetch(); } } \ No newline at end of file +assign([ 'year'=>getMonth('y'), 'real_name'=>$this->request->get('real_name',''), 'orderCount'=>StoreOrderModel::orderCount(), ]); return $this->fetch(); } /** * 获取头部订单金额等信息 * return json * */ public function getBadge(){ $where = Util::postMore([ ['status',''], ['real_name',''], ['is_del',0], ['data',''], ['type',''], ['order',''] ]); return JsonService::successful(StoreOrderModel::getBadge($where)); } /** * 获取订单列表 * return json */ public function order_list(){ $where = Util::getMore([ ['status',''], ['real_name',$this->request->param('real_name','')], ['is_del',0], ['data',''], ['type',''], ['order',''], ['page',1], ['limit',20], ['excel',0] ]); return JsonService::successlayui(StoreOrderModel::OrderList($where)); } public function orderchart(){ $where = Util::getMore([ ['status',''], ['real_name',''], ['is_del',0], ['data',''], ['combination_id',''], ['export',0], ['order','id desc'] ],$this->request); $limitTimeList = [ 'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]), 'week'=>implode(' - ',[ date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)), date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600)) ]), 'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]), 'quarter'=>implode(' - ',[ date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01', date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y'))) ]), 'year'=>implode(' - ',[ date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day')) ]) ]; if($where['data'] == '') $where['data'] = $limitTimeList['today']; $orderCount = [ urlencode('未支付')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(0))->count(), urlencode('未发货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(1))->count(), urlencode('待收货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(2))->count(), urlencode('待评价')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(3))->count(), urlencode('交易完成')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(4))->count(), urlencode('退款中')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-1))->count(), urlencode('已退款')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-2))->count() ]; $model = StoreOrderModel::getOrderWhere($where,new StoreOrderModel())->field('sum(total_num) total_num,count(*) count,sum(total_price) total_price,sum(refund_price) refund_price,from_unixtime(add_time,\'%Y-%m-%d\') add_time') ->group('from_unixtime(add_time,\'%Y-%m-%d\')'); $orderPrice = $model->select()->toArray(); $orderDays = []; $orderCategory = [ ['name'=>'商品数','type'=>'line','data'=>[]], ['name'=>'订单数','type'=>'line','data'=>[]], ['name'=>'订单金额','type'=>'line','data'=>[]], ['name'=>'退款金额','type'=>'line','data'=>[]] ]; foreach ($orderPrice as $price){ $orderDays[] = $price['add_time']; $orderCategory[0]['data'][] = $price['total_num']; $orderCategory[1]['data'][] = $price['count']; $orderCategory[2]['data'][] = $price['total_price']; $orderCategory[3]['data'][] = $price['refund_price']; } $this->assign(StoreOrderModel::systemPage($where,$this->adminId)); $this->assign('price',StoreOrderModel::getOrderPrice($where)); $this->assign(compact('limitTimeList','where','orderCount','orderPrice','orderDays','orderCategory')); return $this->fetch(); } /** * 修改支付金额等 * @param $id * @return mixed|\think\response\Json|void */ public function edit($id) { if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); $f = array(); $f[] = Form::input('order_id','订单编号',$product->getData('order_id'))->disabled(1); $f[] = Form::number('total_price','商品总价',$product->getData('total_price'))->min(0); $f[] = Form::number('total_postage','原始邮费',$product->getData('total_postage'))->min(0); $f[] = Form::number('pay_price','实际支付金额',$product->getData('pay_price'))->min(0); $f[] = Form::number('pay_postage','实际支付邮费',$product->getData('pay_postage')); $f[] = Form::number('gain_integral','赠送积分',$product->getData('gain_integral')); // $f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]); $form = Form::make_post_form('修改订单',$f,Url::build('update',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /** 修改订单提交更新 * @param Request $request * @param $id */ public function update(Request $request, $id) { $data = Util::postMore([ 'order_id', 'total_price', 'total_postage', 'pay_price', 'pay_postage', 'gain_integral', ],$request); if($data['total_price'] <= 0) return Json::fail('请输入商品总价'); if($data['pay_price'] <= 0) return Json::fail('请输入实际支付金额'); $data['order_id'] = StoreOrderModel::changeOrderId($data['order_id']); StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_edit',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'order_edit','修改商品总价为:'.$data['total_price'].' 实际支付金额'.$data['pay_price']); return Json::successful('修改成功!'); } /** * 送货 * @param $id * send */ public function delivery($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1 && $product['status'] == 0) { $f = array(); $f[] = Form::input('delivery_name','送货人姓名')->required('送货人姓名不能为空','required:true;'); $f[] = Form::input('delivery_id','送货人电话')->required('请输入正确电话号码','telephone'); $form = Form::make_post_form('修改订单',$f,Url::build('updateDelivery',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } else return Json::fail('数据不存在!'); } public function updateDelivery(Request $request, $id){ $data = Util::postMore([ 'delivery_name', 'delivery_id', ],$request); $data['delivery_type'] = 'send'; if(!$data['delivery_name']) return Json::fail('请输入送货人姓名'); if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码'); else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码'); $data['status'] = 1; StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_delivery',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']); return Json::successful('修改成功!'); } /** * 发货 * @param $id * express */ public function deliver_goods($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1 && $product['status'] == 0){ $f = array(); $f[] = Form::select('delivery_name','快递公司')->setOptions(function(){ $list = Db::name('express')->where('is_show',1)->order('sort DESC')->column('id,name'); $menus = []; foreach ($list as $k=>$v){ $menus[] = ['value'=>$v,'label'=>$v]; } return $menus; })->filterable(1); $f[] = Form::input('delivery_id','快递单号')->number(1); $form = Form::make_post_form('修改订单',$f,Url::build('updateDeliveryGoods',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } else return Json::fail('数据不存在!'); } /**发货保存 * @param Request $request * @param $id */ public function updateDeliveryGoods(Request $request, $id){ $data = Util::postMore([ 'delivery_name', 'delivery_id', ],$request); $data['delivery_type'] = 'express'; if(!$data['delivery_name']) return Json::fail('请选择快递公司'); if(!$data['delivery_id']) return Json::fail('请输入快递单号'); $data['status'] = 1; StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_delivery_goods',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'delivery_goods','已发货 快递公司:'.$data['delivery_name'].' 快递单号:'.$data['delivery_id']); return Json::successful('修改成功!'); } /** * 修改状态为已收货 * @param $id * @return \think\response\Json|void */ public function take_delivery($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['status'] == 2) return Json::fail('不能重复收货!'); if($product['paid'] == 1 && $product['status'] == 1) $data['status'] = 2; else if($product['pay_type'] == 'offline') $data['status'] = 2; else return Json::fail('请先发货或者送货!'); if(!StoreOrderModel::edit($data,$id)) return Json::fail(StoreOrderModel::getErrorInfo('收货失败,请稍候再试!')); else{ try{ HookService::listen('store_product_order_take_delivery',$data,$id,false,StoreProductBehavior::class); }catch (Exception $e){ return Json::fail($e->getMessage()); } StoreOrderStatus::setStatus($id,'take_delivery','已收货'); return Json::successful('收货成功!'); } } /** * 修改退款状态 * @param $id * @return \think\response\Json|void */ public function refund_y($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1){ $f = array(); $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); $f[] = Form::number('refund_price','退款金额',$product->getData('pay_price'))->precision(2)->min(0.01); $f[] = Form::radio('type','状态',1)->options([['label'=>'直接退款','value'=>1],['label'=>'退款后,返回原状态','value'=>2]]); $form = Form::make_post_form('退款处理',$f,Url::build('updateRefundY',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } else return Json::fail('数据不存在!'); } /**退款处理 * @param Request $request * @param $id */ public function updateRefundY(Request $request, $id){ $data = Util::postMore([ 'refund_price', ['type',1], ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['pay_price'] == $product['refund_price']) return Json::fail('已退完支付金额!不能再退款了'); if(!$data['refund_price']) return Json::fail('请输入退款金额'); $refund_price = $data['refund_price']; $data['refund_price'] = bcadd($data['refund_price'],$product['refund_price'],2); $bj = bccomp((float)$product['pay_price'],(float)$data['refund_price'],2); if($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额'); if($data['type'] == 1){ $data['refund_status'] = 2; }else if($data['type'] == 2){ $data['refund_status'] = 0; } $type = $data['type']; unset($data['type']); $refund_data['pay_price'] = $product['pay_price']; $refund_data['refund_price'] = $refund_price; if($product['pay_type'] == 'weixin'){ if($product['is_channel']){ try{ HookService::listen('routine_pay_order_refund',$product['order_id'],$refund_data,true,PaymentBehavior::class); }catch(\Exception $e){ return Json::fail($e->getMessage()); } }else{ try{ HookService::listen('wechat_pay_order_refund',$product['order_id'],$refund_data,true,PaymentBehavior::class); }catch(\Exception $e){ return Json::fail($e->getMessage()); } } }else if($product['pay_type'] == 'yue'){ ModelBasic::beginTrans(); $res1 = User::bcInc($product['uid'],'now_money',$refund_price,'uid'); $res2 = $res2 = UserBill::income('商品退款',$product['uid'],'now_money','pay_product_refund',$refund_price,$product['id'],$product['pay_price'],'订单退款到余额'.floatval($refund_price).'元'); try{ HookService::listen('store_order_yue_refund',$product,$refund_data,false,StoreProductBehavior::class); }catch (\Exception $e){ ModelBasic::rollbackTrans(); return Json::fail($e->getMessage()); } $res = $res1 && $res2; ModelBasic::checkTrans($res); if(!$res) return Json::fail('余额退款失败!'); } $resEdit = StoreOrderModel::edit($data,$id); if($resEdit){ $data['type'] = $type; if($data['type'] == 1) StorePink::setRefundPink($id); HookService::afterListen('store_product_order_refund_y',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元'); return Json::successful('修改成功!'); }else{ StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元失败'); return Json::successful('修改失败!'); } } public function order_info($oid = '') { if(!$oid || !($orderInfo = StoreOrderModel::get($oid))) return $this->failed('订单不存在!'); $userInfo = User::getUserInfo($orderInfo['uid']); if($userInfo['spread_uid']){ $spread = User::where('uid',$userInfo['spread_uid'])->value('nickname'); }else{ $spread =''; } $this->assign(compact('orderInfo','userInfo','spread')); return $this->fetch(); } public function express($oid = '') { if(!$oid || !($order = StoreOrderModel::get($oid))) return $this->failed('订单不存在!'); if($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!'); $cacheName = $order['order_id'].$order['delivery_id']; $result = CacheService::get($cacheName,null); if($result === null || 1==1){ $result = Express::query($order['delivery_id']); if(is_array($result) && isset($result['result']) && isset($result['result']['deliverystatus']) && $result['result']['deliverystatus'] >= 3) $cacheTime = 0; else $cacheTime = 1800; CacheService::set($cacheName,$result,$cacheTime); } $this->assign([ 'order'=>$order, 'express'=>$result ]); return $this->fetch(); } /** * 修改配送信息 * @param $id * @return mixed|\think\response\Json|void */ public function distribution($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); $f = array(); $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); if($product['delivery_type'] == 'send'){ $f[] = Form::input('delivery_name','送货人姓名',$product->getData('delivery_name')); $f[] = Form::input('delivery_id','送货人电话',$product->getData('delivery_id')); }else if($product['delivery_type'] == 'express'){ $f[] = Form::select('delivery_name','快递公司',$product->getData('delivery_name'))->setOptions(function (){ $list = Db::name('express')->where('is_show',1)->column('id,name'); $menus = []; foreach ($list as $k=>$v){ $menus[] = ['value'=>$v,'label'=>$v]; } return $menus; }); $f[] = Form::input('delivery_id','快递单号',$product->getData('delivery_id')); } $form = Form::make_post_form('配送信息',$f,Url::build('updateDistribution',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /**修改配送信息 * @param Request $request * @param $id */ public function updateDistribution(Request $request, $id){ $data = Util::postMore([ 'delivery_name', 'delivery_id', ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['delivery_type'] == 'send'){ if(!$data['delivery_name']) return Json::fail('请输入送货人姓名'); if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码'); else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码'); }else if($product['delivery_type'] == 'express'){ if(!$data['delivery_name']) return Json::fail('请选择快递公司'); if(!$data['delivery_id']) return Json::fail('请输入快递单号'); } StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_distribution',$data,$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'distribution','修改发货信息为'.$data['delivery_name'].'号'.$data['delivery_id']); return Json::successful('修改成功!'); } /** * 修改退款状态 * @param $id * @return mixed|\think\response\Json|void */ public function refund_n($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); $f[] = Form::input('refund_reason','退款原因')->type('textarea'); $form = Form::make_post_form('退款',$f,Url::build('updateRefundN',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /**不退款原因 * @param Request $request * @param $id */ public function updateRefundN(Request $request, $id){ $data = Util::postMore([ 'refund_reason', ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if(!$data['refund_reason']) return Json::fail('请输入退款原因'); $data['refund_status'] = 0; StoreOrderModel::edit($data,$id); HookService::afterListen('store_product_order_refund_n',$data['refund_reason'],$id,false,StoreProductBehavior::class); StoreOrderStatus::setStatus($id,'refund_n','不退款原因:'.$data['refund_reason']); return Json::successful('修改成功!'); } /** * 立即支付 * @param $id */ public function offline($id){ $res = StoreOrderModel::updateOffline($id); if($res){ try{ HookService::listen('store_product_order_offline',$id,false,StoreProductBehavior::class); }catch (Exception $e){ return Json::fail($e->getMessage()); } StoreOrderStatus::setStatus($id,'offline','线下付款'); return Json::successful('修改成功!'); }else{ return Json::fail('修改失败!'); } } /** * 修改积分和金额 * @param $id * @return mixed|\think\response\Json|void */ public function integral_back($id){ if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($product['paid'] == 1){ $f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1); $f[] = Form::number('back_integral','退积分')->min(0); $form = Form::make_post_form('退积分',$f,Url::build('updateIntegralBack',array('id'=>$id))); $this->assign(compact('form')); return $this->fetch('public/form-builder'); }else{ return Json::fail('参数错误!'); } return $this->fetch('public/form-builder'); } /** 退积分保存 * @param Request $request * @param $id */ public function updateIntegralBack(Request $request, $id){ $data = Util::postMore([ 'back_integral', ],$request); if(!$id) return $this->failed('数据不存在'); $product = StoreOrderModel::get($id); if(!$product) return Json::fail('数据不存在!'); if($data['back_integral'] <= 0) return Json::fail('请输入积分'); if($product['use_integral'] == $product['back_integral']) return Json::fail('已退完积分!不能再积分了'); $back_integral = $data['back_integral']; $data['back_integral'] = bcadd($data['back_integral'],$product['back_integral'],2); $bj = bccomp((float)$product['use_integral'],(float)$data['back_integral'],2); if($bj < 0) return Json::fail('退积分大于支付积分,请修改退积分'); ModelBasic::beginTrans(); $res1 = User::bcInc($product['uid'],'integral',$back_integral,'uid'); $res2 = UserBill::income('商品退积分',$product['uid'],'integral','pay_product_integral_back',$back_integral,$product['id'],$product['pay_price'],'订单退积分'.floatval($back_integral).'积分到用户积分'); try{ HookService::listen('store_order_integral_back',$product,$back_integral,false,StoreProductBehavior::class); }catch (\Exception $e){ ModelBasic::rollbackTrans(); return Json::fail($e->getMessage()); } $res = $res1 && $res2; ModelBasic::checkTrans($res); if(!$res) return Json::fail('退积分失败!'); StoreOrderModel::edit($data,$id); StoreOrderStatus::setStatus($id,'integral_back','商品退积分:'.$data['back_integral']); return Json::successful('退积分成功!'); } public function remark(Request $request){ $data = Util::postMore(['id','remark'],$request); if(!$data['id']) return Json::fail('参数错误!'); if($data['remark'] == '') return Json::fail('请输入要备注的内容!'); $id = $data['id']; unset($data['id']); StoreOrderModel::edit($data,$id); return Json::successful('备注成功!'); } public function order_status($oid){ if(!$oid) return $this->failed('数据不存在'); $this->assign(StoreOrderStatus::systemPage($oid)); return $this->fetch(); } } \ No newline at end of file diff --git a/application/admin/model/finance/FinanceModel.php b/application/admin/model/finance/FinanceModel.php index a22ee662..0242ce24 100644 --- a/application/admin/model/finance/FinanceModel.php +++ b/application/admin/model/finance/FinanceModel.php @@ -227,8 +227,8 @@ class FinanceModel extends ModelBasic { $trans = self::alias('a') ->join('user b', 'a.uid=b.uid') - ->join('store_order_cart_info c', 'a.id=c.oid') - ->join('store_product d', 'c.product_id=d.id') + ->join('__STORE_ORDER_CART_INFO__ c', 'a.id=c.oid') + ->join('__STORE_PRODUCT__ d', 'c.product_id=d.id') ->field('b.nickname,a.pay_price,d.store_name') ->order('a.add_time DESC') ->limit('6') diff --git a/application/admin/model/order/StoreOrder.php b/application/admin/model/order/StoreOrder.php index a341e19c..d30c8f22 100644 --- a/application/admin/model/order/StoreOrder.php +++ b/application/admin/model/order/StoreOrder.php @@ -49,7 +49,7 @@ class StoreOrder extends ModelBasic } $data=($data=$model->page((int)$where['page'],(int)$where['limit'])->select()) && count($data) ? $data->toArray() : []; foreach ($data as &$item){ - $_info = db('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select(); + $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select(); foreach ($_info as $k=>$v){ $_info[$k]['cart_info'] = json_decode($v['cart_info'],true); } @@ -157,7 +157,7 @@ HTML; public static function SaveExcel($list){ $export = []; foreach ($list as $index=>$item){ - $_info = db('store_order_cart_info')->where('oid',$item['id'])->column('cart_info'); + $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->column('cart_info'); $goodsName = []; foreach ($_info as $k=>$v){ $v = json_decode($v,true); @@ -209,7 +209,7 @@ HTML; $payType = '其他支付'; } - $_info = db('store_order_cart_info')->where('oid',$item['id'])->column('cart_info'); + $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->column('cart_info'); $goodsName = []; foreach ($_info as $k=>$v){ $v = json_decode($v,true); @@ -237,7 +237,7 @@ HTML; ->ExcelSave(); } return self::page($model,function ($item){ - $_info = db('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select(); + $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select(); foreach ($_info as $k=>$v){ $_info[$k]['cart_info'] = json_decode($v['cart_info'],true); } @@ -513,7 +513,7 @@ HTML; $payType = '其他支付'; } - $_info = db('store_order_cart_info')->where('oid',$item['id'])->column('cart_info'); + $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->column('cart_info'); $goodsName = []; foreach ($_info as $k=>$v){ $v = json_decode($v,true); @@ -540,7 +540,7 @@ HTML; return self::page($model,function ($item){ $item['nickname'] = WechatUser::where('uid',$item['uid'])->value('nickname'); - $_info = db('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select(); + $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select(); foreach ($_info as $k=>$v){ $_info[$k]['cart_info'] = json_decode($v['cart_info'],true); } diff --git a/application/admin/model/record/StoreStatistics.php b/application/admin/model/record/StoreStatistics.php index 10c04cda..04fe9cd3 100644 --- a/application/admin/model/record/StoreStatistics.php +++ b/application/admin/model/record/StoreStatistics.php @@ -173,8 +173,8 @@ class StoreStatistics extends ModelBasic { $trans = self::alias('a') ->join('user b', 'a.uid=b.uid') - ->join('store_order_cart_info c', 'a.id=c.oid') - ->join('store_product d', 'c.product_id=d.id') + ->join('__STORE_ORDER_CART_INFO__ c', 'a.id=c.oid') + ->join('__STORE_PRODUCT__ d', 'c.product_id=d.id') ->field('b.nickname,a.pay_price,d.store_name') ->order('a.add_time DESC') ->limit('6') @@ -200,6 +200,8 @@ class StoreStatistics extends ModelBasic $cost=$info['cost'];//成本 $export[] = [$time,$price,$zhichu,$cost,$coupon,$deduction,$profit]; } +// ExportService::exportCsv($export,'统计'.time(),['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)']); + dump($export); PHPExcelService::setExcelHeader(['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)'])->setExcelTile('财务统计', '财务统计',date('Y-m-d H:i:s',time()))->setExcelContent($export)->ExcelSave(); } } diff --git a/application/admin/model/store/StoreCouponUser.php b/application/admin/model/store/StoreCouponUser.php index 4300f71c..3e3a2a01 100644 --- a/application/admin/model/store/StoreCouponUser.php +++ b/application/admin/model/store/StoreCouponUser.php @@ -4,6 +4,7 @@ namespace app\admin\model\store; use basic\ModelBasic; use traits\ModelTrait; +use think\Db; class StoreCouponUser extends ModelBasic { @@ -38,7 +39,7 @@ class StoreCouponUser extends ModelBasic $coupon['_msg'] = '可使用'; } } - $coupon['integral']=db('store_coupon')->where(['id'=>$coupon['cid']])->value('integral'); + $coupon['integral']= Db::name('store_coupon')->where(['id'=>$coupon['cid']])->value('integral'); } return $couponList; } @@ -53,7 +54,7 @@ class StoreCouponUser extends ModelBasic [ 'name'=>'总发放优惠券', 'field'=>'张', - 'count'=>self::getModelTime($where,db('store_coupon_issue'))->where('status',1)->sum('total_count'), + 'count'=>self::getModelTime($where, Db::name('store_coupon_issue'))->where('status',1)->sum('total_count'), 'background_color'=>'layui-bg-blue', 'col'=>6, ], @@ -69,7 +70,7 @@ class StoreCouponUser extends ModelBasic //获取优惠劵图表 public static function getConponCurve($where,$limit=20){ //优惠劵发放记录 - $list=self::getModelTime($where,db('store_coupon_issue') + $list=self::getModelTime($where, Db::name('store_coupon_issue') ->where('status',1) ->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(total_count) as total_count'])->group('_add_time')->order('_add_time asc'))->select(); $date=[]; diff --git a/application/admin/model/store/StoreProduct.php b/application/admin/model/store/StoreProduct.php index c8ac0c05..3723f30e 100644 --- a/application/admin/model/store/StoreProduct.php +++ b/application/admin/model/store/StoreProduct.php @@ -384,7 +384,7 @@ class StoreProduct extends ModelBasic }else{ $time['data']=isset($where['data'])? $where['data']:''; } - $model=self::getModelTime($time,db('store_cart')->alias('a')->join('__STORE_PRODUCT__ b','a.product_id=b.id'),'a.add_time'); + $model=self::getModelTime($time, Db::name('store_cart')->alias('a')->join('__STORE_PRODUCT__ b','a.product_id=b.id'),'a.add_time'); if(isset($where['title']) && $where['title']!=''){ $model=$model->where('b.store_name|b.id','like',"%$where[title]%"); } diff --git a/application/admin/model/ump/StoreSeckill.php b/application/admin/model/ump/StoreSeckill.php index f3c69d0d..56c8a5f3 100644 --- a/application/admin/model/ump/StoreSeckill.php +++ b/application/admin/model/ump/StoreSeckill.php @@ -161,7 +161,7 @@ class StoreSeckill extends ModelBasic */ public static function getMaxList($where){ $classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan']; - $model=StoreOrder::alias('a')->join('store_seckill b','b.id=a.seckill_id')->where('a.paid',1); + $model=StoreOrder::alias('a')->join('__STORE_SECKILL__ b','b.id=a.seckill_id')->where('a.paid',1); $list=self::getModelTime($where,$model,'a.add_time')->group('a.seckill_id')->order('p_count desc')->limit(10) ->field(['count(a.seckill_id) as p_count','b.title as store_name','sum(b.price) as sum_price'])->select(); if(count($list)) $list=$list->toArray(); @@ -191,7 +191,7 @@ class StoreSeckill extends ModelBasic */ public static function ProfityTop10($where){ $classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan']; - $model = StoreOrder::alias('a')->join('store_seckill b','b.id = a.seckill_id')->where('a.paid',1); + $model = StoreOrder::alias('a')->join('__STORE_SECKILL__ b','b.id = a.seckill_id')->where('a.paid',1); $list=self::getModelTime($where,$model,'a.add_time')->group('a.seckill_id')->order('profity desc')->limit(10) ->field(['count(a.seckill_id) as p_count','b.title as store_name','sum(b.price) as sum_price','(b.price-b.cost) as profity']) ->select(); @@ -244,7 +244,7 @@ class StoreSeckill extends ModelBasic * @return mixed */ public static function getBargainRefundList($where = array()){ - $model = StoreOrder::alias('a')->join('store_seckill b','b.id=a.seckill_id'); + $model = StoreOrder::alias('a')->join('__STORE_SECKILL__ b','b.id=a.seckill_id'); $list = self::getModelTime($where,$model,'a.add_time')->where('a.refund_status','NEQ',0)->group('a.seckill_id')->order('count desc')->page((int)$where['page'],(int)$where['limit']) ->field(['count(a.seckill_id) as count','b.title as store_name','sum(b.price) as sum_price'])->select(); if(count($list)) $list=$list->toArray(); diff --git a/application/admin/model/user/User.php b/application/admin/model/user/User.php index 86a23e66..43e82e83 100644 --- a/application/admin/model/user/User.php +++ b/application/admin/model/user/User.php @@ -1 +1 @@ - * @day: 2017/11/11 */ namespace app\admin\model\user; use app\admin\model\order\StoreOrder; use traits\ModelTrait; use app\wap\model\user\UserBill; use basic\ModelBasic; use app\admin\model\wechat\WechatUser; use app\admin\model\store\StoreCouponUser; use app\admin\model\user\UserExtract; /** * 用户管理 model * Class User * @package app\admin\model\user */ class User extends ModelBasic { use ModelTrait; /** * @param $where * @return array */ public static function systemPage($where){ $model = new self; if($where['status'] != '') $model = $model->where('status',$where['status']); if($where['is_promoter'] != '') $model = $model->where('is_promoter',$where['is_promoter']); if(isset($where['user_type']) && $where['user_type'] != '') $model = $model->where('user_type',$where['user_type']); if($where['nickname'] != '') $model = $model->where('nickname|uid','like',"%$where[nickname]%"); $model = $model->order('uid desc'); return self::page($model,function ($item){ if($item['spread_uid']){ $item['spread_uid_nickname'] = self::where('uid',$item['spread_uid'])->value('nickname'); }else{ $item['spread_uid_nickname'] = '无'; } },$where); } /* * 设置搜索条件 * */ public static function setWhere($where) { if($where['order']!=''){ $model=self::order(self::setOrder($where['order'])); }else{ $model=self::order('u.uid desc'); } if($where['user_time_type'] == 'visitno' && $where['user_time'] != ''){ list($startTime, $endTime) = explode(' - ', $where['user_time']); $model = $model->where('u.last_time', ['>', strtotime($endTime)+24*3600], ['<', strtotime($startTime)],'or'); } if($where['user_time_type'] == 'visit' && $where['user_time'] != ''){ list($startTime, $endTime) = explode(' - ', $where['user_time']); $model = $model->where('u.last_time', '>', strtotime($startTime)); $model = $model->where('u.last_time', '<', strtotime($endTime)+24*3600); } if($where['user_time_type'] == 'add_time' && $where['user_time'] != ''){ list($startTime, $endTime) = explode(' - ', $where['user_time']); $model = $model->where('u.add_time', '>', strtotime($startTime)); $model = $model->where('u.add_time', '<', strtotime($endTime)+24*3600); } if($where['pay_count'] !== '') { if($where['pay_count'] == '-1') $model = $model->where('pay_count',0); else $model = $model->where('pay_count','>',$where['pay_count']); } if($where['user_type'] != ''){ if($where['user_type'] == 'routine') $model = $model->where('w.routine_openid','not null'); else if($where['user_type'] == 'wechat') $model = $model->where('w.openid','not null'); } if($where['country'] != ''){ if($where['country'] == 'domestic') $model = $model->where('w.country','EQ','中国'); else if($where['country'] == 'abroad') $model = $model->where('w.country','NEQ','中国'); } return $model; } /** * 异步获取当前用户 信息 * @param $where * @return array */ public static function getUserList($where){ $model = self::setWherePage(self::setWhere($where),$where,['w.sex','w.province','w.city','u.status','u.is_promoter'],['u.nickname','u.uid']); $list = $model->alias('u') ->join('WechatUser w','u.uid=w.uid') ->field('u.*,w.country,w.province,w.city,w.sex,w.unionid,w.openid,w.routine_openid,w.groupid,w.tagid_list,w.subscribe,w.subscribe_time') ->page((int)$where['page'],(int)$where['limit']) ->select() ->each(function ($item){ $item['add_time']=date('Y-m-d H:i:s',$item['add_time']); if($item['last_time']) $item['last_time'] = date('Y-m-d H:i:s',$item['last_time']);//最近一次访问日期 else $item['last_time'] = '无访问';//最近一次访问日期 self::edit(['pay_count'=>StoreOrder::getUserCountPay($item['uid'])],$item['uid']); $item['extract_count_price'] = UserExtract::getUserCountPrice($item['uid']);//累计提现 if($item['spread_uid']){ $item['spread_uid_nickname'] = self::where('uid',$item['spread_uid'])->value('nickname').'/'.$item['spread_uid']; }else{ $item['spread_uid_nickname'] = '无'; } if($item['openid'] != '' && $item['routine_openid'] != ''){ $item['user_type']='公众号小程序类型'; }else if($item['openid'] == '' && $item['routine_openid'] != ''){ $item['user_type']='小程序类型'; }else if($item['openid'] != '' && $item['routine_openid'] == ''){ $item['user_type']='公众号类型'; }else $item['user_type']='其他类型'; if($item['sex'] == 1){ $item['sex']='男'; }else if($item['sex'] == 2){ $item['sex']='女'; }else $item['sex']='保密'; })->toArray(); $count=self::setWherePage(self::setWhere($where),$where,['w.sex','w.province','w.city','u.status','u.is_promoter'],['u.nickname','u.uid'])->alias('u')->join('WechatUser w','u.uid=w.uid')->count(); return ['count'=>$count,'data'=>$list]; } /** * 修改用户状态 * @param $uids 用户uid * @param $status 修改状态 * @return array */ public static function destrSyatus($uids,$status){ if(empty($uids) && !is_array($uids)) return false; if($status=='') return false; self::beginTrans(); try{ $res=self::where('uid','in',$uids)->update(['status'=>$status]); self::checkTrans($res); return true; }catch (\Exception $e){ self::rollbackTrans(); return Json::fail($e->getMessage()); } } /* * 获取某季度,某年某年后的时间戳 * * self::getMonth('n',1) 获取当前季度的上个季度的时间戳 * self::getMonth('n') 获取当前季度的时间戳 */ public static function getMonth($time='',$ceil=0){ if(empty($time)){ $firstday = date("Y-m-01",time()); $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day")); }else if($time=='n'){ if($ceil!=0) $season = ceil(date('n') /3)-$ceil; else $season = ceil(date('n') /3); $firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y'))); $lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y'))); }else if($time=='y'){ $firstday=date('Y-01-01'); $lastday=date('Y-12-31'); }else if($time=='h'){ $firstday = date('Y-m-d', strtotime('this week +'.$ceil.' day')) . ' 00:00:00'; $lastday = date('Y-m-d', strtotime('this week +'.($ceil+1).' day')) . ' 23:59:59'; } return array($firstday,$lastday); } public static function getcount(){ return self::count(); } /* *获取用户某个时间段的消费信息 * * reutrn Array || number */ public static function consume($where,$status='',$keep=''){ $model = new self; $user_id=[]; if(is_array($where)){ if($where['is_promoter']!='') $model=$model->where('is_promoter',$where['is_promoter']); if($where['status']!='') $model=$model->where('status',$where['status']); switch ($where['date']){ case null:case 'today':case 'week':case 'year': if($where['date']==null){ $where['date']='month'; } if($keep){ $model=$model->whereTime('add_time',$where['date'])->whereTime('last_time',$where['date']); }else{ $model=$model->whereTime('add_time',$where['date']); } break; case 'quarter': $quarter=self::getMonth('n'); $startTime=strtotime($quarter[0]); $endTime=strtotime($quarter[1]); if($keep){ $model = $model->where('add_time','>',$startTime)->where('add_time','<',$endTime)->where('last_time','>',$startTime)->where('last_time','<',$endTime); }else{ $model = $model->where('add_time','>',$startTime)->where('add_time','<',$endTime); } break; default: //自定义时间 if(strstr($where['date'],'-')!==FALSE){ list($startTime,$endTime)=explode('-',$where['date']); $model = $model->where('add_time','>',strtotime($startTime))->where('add_time','<',strtotime($endTime)); }else{ $model=$model->whereTime('add_time','month'); } break; } }else{ if(is_array($status)){ $model=$model->where('add_time','>',$status[0])->where('add_time','<',$status[1]); } } if($keep===true){ return $model->count(); } if($status==='default'){ return $model->group('from_unixtime(add_time,\'%Y-%m-%d\')')->field('count(uid) num,from_unixtime(add_time,\'%Y-%m-%d\') add_time,uid')->select()->toArray(); } if($status==='grouping'){ return $model->group('user_type')->field('user_type')->select()->toArray(); } $uid=$model->field('uid')->select()->toArray(); foreach ($uid as $val){ $user_id[]=$val['uid']; } if(empty($user_id)){ $user_id=[0]; } if($status==='xiaofei'){ $list=UserBill::where('uid','in',$user_id) ->group('type') ->field('sum(number) as top_number,title') ->select() ->toArray(); $series=[ 'name'=>isset($list[0]['title'])?$list[0]['title']:'', 'type'=>'pie', 'radius'=> ['40%', '50%'], 'data'=>[] ]; foreach($list as $key=>$val){ $series['data'][$key]['value']=$val['top_number']; $series['data'][$key]['name']=$val['title']; } return $series; }else if($status==='form'){ $list=WechatUser::where('uid','in',$user_id)->group('city')->field('count(city) as top_city,city')->limit(0,10)->select()->toArray(); $count=self::getcount(); $option=[ 'legend_date'=>[], 'series_date'=>[] ]; foreach($list as $key=>$val){ $num=$count!=0?(bcdiv($val['top_city'],$count,2))*100:0; $t=['name'=>$num.'% '.(empty($val['city'])?'未知':$val['city']),'icon'=>'circle']; $option['legend_date'][$key]=$t; $option['series_date'][$key]=['value'=>$num,'name'=>$t['name']]; } return $option; }else{ $number=UserBill::where('uid','in',$user_id)->where('type','pay_product')->sum('number'); return $number; } } /* * 获取 用户某个时间段的钱数或者TOP20排行 * * return Array || number */ public static function getUserSpend($date,$status=''){ $model=new self(); $model=$model->alias('A'); switch ($date){ case null:case 'today':case 'week':case 'year': if($date==null) $date='month'; $model=$model->whereTime('A.add_time',$date); break; case 'quarter': list($startTime,$endTime)=User::getMonth('n'); $model = $model->where('A.add_time','>',strtotime($startTime)); $model = $model->where('A.add_time','<',strtotime($endTime)); break; default: list($startTime,$endTime)=explode('-',$date); $model = $model->where('A.add_time','>',strtotime($startTime)); $model = $model->where('A.add_time','<',strtotime($endTime)); break; } if($status===true){ return $model->join('user_bill B','B.uid=A.uid')->where('B.type','pay_product')->where('B.pm',0)->sum('B.number'); } $list=$model->join('user_bill B','B.uid=A.uid') ->where('B.type','pay_product') ->where('B.pm',0) ->field('sum(B.number) as totel_number,A.nickname,A.avatar,A.now_money,A.uid,A.add_time') ->order('totel_number desc') ->limit(0,20) ->select() ->toArray(); if(!isset($list[0]['totel_number'])){ $list=[]; } return $list; } /* * 获取 相对于上月或者其他的数据 * * return Array */ public static function getPostNumber($date,$status=false,$field='A.add_time',$t='消费'){ $model=new self(); if(!$status) $model=$model->alias('A'); switch ($date){ case null:case 'today':case 'week':case 'year': if($date==null) { $date='last month'; $title='相比上月用户'.$t.'增长'; } if($date=='today') { $date='yesterday'; $title='相比昨天用户'.$t.'增长'; } if($date=='week') { $date='last week'; $title='相比上周用户'.$t.'增长'; } if($date=='year') { $date='last year'; $title='相比去年用户'.$t.'增长'; } $model=$model->whereTime($field,$date); break; case 'quarter': $title='相比上季度用户'.$t.'增长'; list($startTime,$endTime)=User::getMonth('n',1); $model = $model->where($field,'>',$startTime); $model = $model->where($field,'<',$endTime); break; default: list($startTime,$endTime)=explode('-',$date); $title='相比'.$startTime.'-'.$endTime.'时间段用户'.$t.'增长'; $Time=strtotime($endTime)-strtotime($startTime); $model = $model->where($field,'>',strtotime($startTime)+$Time); $model = $model->where($field,'<',strtotime($endTime)+$Time); break; } if($status){ return [$model->count(),$title]; } $number=$model->join('user_bill B','B.uid=A.uid')->where('B.type','pay_product')->where('B.pm',0)->sum('B.number'); return [$number,$title]; } //获取用户新增,头部信息 public static function getBadgeList($where){ $user_count=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])->count(); $user_count_old=self::getOldDate($where)->count(); $fenxiao=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])->where('spread_uid','<>',0)->count(); $fenxiao_count=self::getOldDate($where)->where('spread_uid','neq',0)->count(); $newFemxiao_count=bcsub($fenxiao,$fenxiao_count,0); $order_count=bcsub($user_count,$user_count_old,0); return [ [ 'name'=>'会员人数', 'field'=>'个', 'count'=>$user_count, 'content'=>'会员总人数', 'background_color'=>'layui-bg-blue', 'sum'=>self::count(), 'class'=>'fa fa-bar-chart', ], [ 'name'=>'会员增长', 'field'=>'个', 'count'=>$order_count, 'content'=>'会员增长率', 'background_color'=>'layui-bg-cyan', 'sum'=>$user_count_old ? bcdiv($order_count,$user_count_old,2)*100:0, 'class'=>'fa fa-line-chart', ], [ 'name'=>'分销人数', 'field'=>'个', 'count'=>$fenxiao, 'content'=>'分销总人数', 'background_color'=>'layui-bg-green', 'sum'=>self::where('spread_uid','neq',0)->count(), 'class'=>'fa fa-bar-chart', ], [ 'name'=>'分销增长', 'field'=>'个', 'count'=>$newFemxiao_count, 'content'=>'分销总人数', 'background_color'=>'layui-bg-orange', 'sum'=>$fenxiao_count ? bcdiv($newFemxiao_count,$fenxiao_count,2)*100:0, 'class'=>'fa fa-cube', ], ]; } /* * 获取会员增长曲线图和分布图 * $where 查询条件 * $limit 显示条数,是否有滚动条 */ public static function getUserChartList($where,$limit=20){ $list=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status']) ->where('add_time','neq',0) ->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','count(uid) as num']) ->order('_add_time asc') ->group('_add_time') ->select(); count($list) && $list=$list->toArray(); $seriesdata=[]; $xdata=[]; $Zoom=''; foreach ($list as $item){ $seriesdata[]=$item['num']; $xdata[]=$item['_add_time']; } (count($xdata) > $limit) && $Zoom=$xdata[$limit-5]; //多次购物会员数量饼状图 $count=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter'])->count(); $user_count=self::setWherePage(self::getModelTime($where,self::alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time'),$where,['is_promoter']) ->where('r.paid',1)->count('a.uid'); $shop_xdata=['多次购买数量占比','无购买数量占比']; $shop_data=[]; $count >0 && $shop_data=[ [ 'value'=>bcdiv($user_count,$count,2)*100, 'name'=>$shop_xdata[0], 'itemStyle'=>[ 'color'=>'#D789FF', ] ], [ 'value'=>bcdiv($count-$user_count,$count,2)*100, 'name'=>$shop_xdata[1], 'itemStyle'=>[ 'color'=>'#7EF0FB', ] ] ]; return compact('shop_data','shop_xdata','fenbu_data','fenbu_xdata','seriesdata','xdata','Zoom'); } //获取$date的前一天或者其他的时间段 public static function getOldDate($where,$moedls=null){ $model=$moedls ===null ? self::setWherePage(new self(),$where,['is_promoter','status']) :$moedls; switch ($where['data']){ case 'today': $model=$model->whereTime('add_time','yesterday'); break; case 'week': $model=$model->whereTime('add_time','last week'); break; case 'month': $model=$model->whereTime('add_time','last month'); break; case 'year': $model=$model->whereTime('add_time','last year'); break; case 'quarter': $time=self::getMonth('n',1); $model=$model->where('add_time','between',$time); break; } return $model; } //获取用户属性和性别分布图 public static function getEchartsData($where){ $model=self::alias('a'); $data=self::getModelTime($where,$model,'a.add_time') ->join('wechat_user r','r.uid=a.uid') ->group('r.province') ->field('count(r.province) as count,province') ->order('count desc') ->limit(15) ->select(); if(count($data)) $data=$data->toArray(); $legdata=[]; $dataList=[]; foreach ($data as $value){ $value['province']=='' && $value['province']='未知省份'; $legdata[]=$value['province']; $dataList[]=$value['count']; } $model=self::alias('a'); $sex=self::getModelTime($where,$model,'a.add_time') ->join('wechat_user r','r.uid=a.uid') ->group('r.sex') ->field('count(r.uid) as count,sex') ->order('count desc') ->select(); if(count($sex)) $sex=$sex->toArray(); $sexlegdata=['男','女','未知']; $sexcount=self::getModelTime($where,new self())->count(); $sexList=[]; $color=['#FB7773','#81BCFE','#91F3FE']; foreach ($sex as $key=>$item){ if($item['sex']==1){ $item_date['name']='男'; }else if($item['sex']==2){ $item_date['name']='女'; }else{ $item_date['name']='未知性别'; } $item_date['value']=bcdiv($item['count'],$sexcount,2)*100; $item_date['itemStyle']['color']=$color[$key]; $sexList[]=$item_date; } return compact('sexList','sexlegdata','legdata','dataList'); } //获取佣金记录列表 public static function getCommissionList($where){ $list=self::setCommissionWhere($where) ->page((int)$where['page'],(int)$where['limit']) ->select(); count($list) && $list=$list->toArray(); foreach ($list as &$value){ $value['ex_price']=db('user_extract')->where(['uid'=>$value['uid']])->sum('extract_price'); $value['extract_price']=db('user_extract')->where(['uid'=>$value['uid'],'status'=>1])->sum('extract_price'); } $count=self::setCommissionWhere($where)->count(); return ['data'=>$list,'count'=>$count]; } //获取佣金记录列表的查询条件 public static function setCommissionWhere($where){ $models=self::setWherePage(self::alias('A'),$where,[],['A.nickname','A.uid']) ->join('user_bill B','B.uid=A.uid') ->group('A.uid') ->where(['B.category'=>'now_money','B.type'=>'brokerage']) ->field(['sum(B.number) as sum_number','A.nickname','A.uid','A.now_money']); if($where['order']==''){ $models=$models->order('sum_number desc'); }else{ $models=$models->order($where['order']==1 ? 'sum_number desc':'sum_number asc'); } if($where['price_max']!='' && $where['price_min']!=''){ $models=$models->where('now_money','between',[$where['price_max'],$where['price_min']]); } return $models; } //获取某人用户推广信息 public static function getUserinfo($uid){ $userinfo=self::where(['uid'=>$uid])->field(['nickname','spread_uid','now_money','add_time'])->find()->toArray(); $userinfo['number']=UserBill::where(['category'=>'now_money','type'=>'brokerage'])->sum('number'); $userinfo['spread_name']=$userinfo['spread_uid'] ? self::where(['uid'=>$userinfo['spread_uid']])->value('nickname') :''; return $userinfo; } //获取某用户的详细信息 public static function getUserDetailed($uid){ $key_field=['real_name','phone','province','city','district','detail','post_code']; $Address=($thisAddress=db('user_address')->where(['uid'=>$uid,'is_default'=>1])->field($key_field)->find()) ? $thisAddress : db('user_address')->where(['uid'=>$uid])->field($key_field)->find(); $UserInfo=self::get($uid); return [ ['col'=>12,'name'=>'默认收货地址','value'=>$thisAddress ? '收货人:'.$thisAddress['real_name'].'邮编:'.$thisAddress['post_code'].' 收货人电话:'.$thisAddress['phone'].' 地址:'.$thisAddress['province'].' '.$thisAddress['city'].' '.$thisAddress['district'].' '.$thisAddress['detail'] : ''], // ['name'=>'微信OpenID','value'=>WechatUser::where(['uid'=>$uid])->value('openid'),'col'=>8], ['name'=>'手机号码','value'=>$UserInfo['phone']], // ['name'=>'ID','value'=>$uid], ['name'=>'姓名','value'=>''], ['name'=>'微信昵称','value'=>$UserInfo['nickname']], ['name'=>'邮箱','value'=>''], ['name'=>'生日','value'=>''], ['name'=>'积分','value'=>UserBill::where(['category'=>'integral','uid'=>$uid])->where('type','in',['sign','system_add'])->sum('number')], ['name'=>'上级推广人','value'=>$UserInfo['spread_uid'] ? self::where(['uid'=>$UserInfo['spread_uid']])->value('nickname'):''], ['name'=>'账户余额','value'=>$UserInfo['now_money']], ['name'=>'佣金总收入','value'=>UserBill::where(['category'=>'now_money','type'=>'brokerage','uid'=>$uid])->sum('number')], ['name'=>'提现总金额','value'=>db('user_extract')->where(['uid'=>$uid,'status'=>1])->sum('extract_price')], ]; } //获取某用户的订单个数,消费明细 public static function getHeaderList($uid){ return [ [ 'title'=>'总计订单', 'value'=>StoreOrder::where(['uid'=>$uid])->count(), 'key'=>'笔', 'class'=>'', ], [ 'title'=>'总消费金额', 'value'=>StoreOrder::where(['uid'=>$uid,'paid'=>1])->sum('total_price'), 'key'=>'元', 'class'=>'', ], [ 'title'=>'本月订单', 'value'=>StoreOrder::where(['uid'=>$uid])->whereTime('add_time','month')->count(), 'key'=>'笔', 'class'=>'', ], [ 'title'=>'本月消费金额', 'value'=>StoreOrder::where(['uid'=>$uid])->whereTime('add_time','month')->sum('total_price'), 'key'=>'元', 'class'=>'', ] ]; } /* * 获取 会员 订单个数,积分明细,优惠劵明细 * * $uid 用户id; * * return array */ public static function getCountInfo($uid){ $order_count=StoreOrder::where(['uid'=>$uid])->count(); $integral_count=UserBill::where(['uid'=>$uid,'category'=>'integral'])->where('type','in',['deduction','system_add'])->count(); $sign_count=UserBill::where(['uid'=>$uid,'category'=>'integral','type'=>'sign'])->count(); $balanceChang_count=UserBill::where(['uid'=>$uid,'category'=>'now_money']) ->where('type','in',['system_add','pay_product','extract','pay_product_refund','system_sub']) ->count(); $coupon_count=StoreCouponUser::where(['uid'=>$uid])->count(); $spread_count=self::where(['spread_uid'=>$uid])->count(); return compact('order_count','integral_count','sign_count','balanceChang_count','coupon_count','spread_count'); } /* * 获取 会员业务的 * 购物会员统计 * 会员访问量 * * 曲线图 * * $where 查询条件 * * return array */ public static function getUserBusinessChart($where,$limit=20){ //获取购物会员人数趋势图 $list=self::getModelTime($where,self::where('a.status',1)->alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time') ->where(['r.paid'=>1,'a.is_promoter'=>0]) ->where('a.add_time','neq',0) ->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','count(r.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($list) && $list=$list->toArray(); $seriesdata=[]; $xdata=[]; $zoom=''; foreach ($list as $item){ $seriesdata[]=$item['count_user']; $xdata[]=$item['_add_time']; } count($xdata) > $limit && $zoom=$xdata[$limit-5]; //会员访问量 $visit=self::getModelTime($where,self::alias('a')->join('__STORE_VISIT__ t','t.uid=a.uid'),'t.add_time') ->where('a.is_promoter',0) ->field(['FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time','count(t.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($visit) && $visit=$visit->toArray(); $visit_data=[]; $visit_xdata=[]; $visit_zoom=''; foreach ($visit as $item){ $visit_data[]=$item['count_user']; $visit_xdata[]=$item['_add_time']; } count($visit_xdata) > $limit && $visit_zoom=$visit_xdata[$limit-5]; //多次购物会员数量饼状图 $count=self::getModelTime($where,self::where('is_promoter',0))->count(); $user_count=self::getModelTime($where,self::alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time') ->where('a.is_promoter',0) ->where('r.paid',1) ->group('a.uid') ->count(); $shop_xdata=['多次购买数量占比','无购买数量占比']; $shop_data=[]; $count >0 && $shop_data=[ [ 'value'=>bcdiv($user_count,$count,2)*100, 'name'=>$shop_xdata[0], 'itemStyle'=>[ 'color'=>'#D789FF', ] ], [ 'value'=>bcdiv($count-$user_count,$count,2)*100, 'name'=>$shop_xdata[1], 'itemStyle'=>[ 'color'=>'#7EF0FB', ] ] ]; return compact('seriesdata','xdata','zoom','visit_data','visit_xdata','visit_zoom','shop_data','shop_xdata'); } /* * 获取用户 * 积分排行 * 会员余额排行榜 * 分销商佣金总额排行榜 * 购物笔数排行榜 * 购物金额排行榜 * 分销商佣金提现排行榜 * 上月消费排行榜 * $limit 查询多少条 * return array */ public static function getUserTop10List($limit=10,$is_promoter=0){ //积分排行 $integral=self::where('status',1) ->where('is_promoter',$is_promoter) ->order('integral desc') ->field(['nickname','phone','integral','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time']) ->limit($limit) ->select(); count($integral) && $integral=$integral->toArray(); //会员余额排行榜 $now_money=self::where('status',1) ->where('is_promoter',$is_promoter) ->order('now_money desc') ->field(['nickname','phone','now_money','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time']) ->limit($limit) ->select(); count($now_money) && $now_money=$now_money->toArray(); //购物笔数排行榜 $shopcount=self::alias('a') ->join('store_order r','r.uid=a.uid') ->where(['r.paid'=>1,'a.is_promoter'=>$is_promoter]) ->group('r.uid') ->field(['a.nickname','a.phone','count(r.uid) as sum_count','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time']) ->order('sum_count desc') ->limit($limit) ->select(); count($shopcount) && $shopcount=$shopcount->toArray(); //购物金额排行榜 $order=self::alias('a') ->join('store_order r','r.uid=a.uid') ->where(['r.paid'=>1,'a.is_promoter'=>$is_promoter]) ->group('r.uid') ->field(['a.nickname','a.phone','sum(r.pay_price) as sum_price','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time','r.uid']) ->order('sum_price desc') ->limit($limit) ->select(); count($order) && $order=$order->toArray(); //上月消费排行 $lastorder=self::alias('a') ->join('store_order r','r.uid=a.uid') ->where(['r.paid'=>1,'a.is_promoter'=>$is_promoter]) ->whereTime('r.pay_time','last month') ->group('r.uid') ->field(['a.nickname','a.phone','sum(r.pay_price) as sum_price','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time','r.uid']) ->order('sum_price desc') ->limit($limit) ->select(); return compact('integral','now_money','shopcount','order','lastorder'); } /* * 获取 会员业务 * 会员总余额 会员总积分 * $where 查询条件 * * return array */ public static function getUserBusinesHeade($where){ return [ [ 'name'=>'会员总余额', 'field'=>'元', 'count'=>self::getModelTime($where,self::where('status',1))->sum('now_money'), 'background_color'=>'layui-bg-cyan', 'col'=>6, ], [ 'name'=>'会员总积分', 'field'=>'分', 'count'=>self::getModelTime($where,self::where('status',1))->sum('integral'), 'background_color'=>'layui-bg-cyan', 'col'=>6 ] ]; } /* * 分销会员头部信息查询获取 * * 分销商总佣金余额 * 分销商总提现佣金 * 本月分销商业务佣金 * 本月分销商佣金提现金额 * 上月分销商业务佣金 * 上月分销商佣金提现金额 * $where array 时间条件 * * return array */ public static function getDistributionBadgeList($where){ return [ [ 'name'=>'分销商总佣金', 'field'=>'元', 'count'=>self::getModelTime($where,UserBill::where('category','now_money')->where('type','brokerage'))->where('uid','in',function($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'分销商总佣金余额', 'field'=>'元', 'count'=>self::getModelTime($where,self::where('status',1)->where('is_promoter',1))->sum('now_money'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'分销商总提现佣金', 'field'=>'元', 'count'=>self::getModelTime($where,UserExtract::where('status',1))->sum('extract_price'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'本月分销商业务佣金', 'field'=>'元', 'count'=>self::getModelTime(['data'=>'month'],UserBill::where('category','now_money')->where('type','brokerage')) ->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'本月分销商佣金提现金额', 'field'=>'元', 'count'=>self::getModelTime(['data'=>'month'],UserExtract::where('status',1)) ->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->field('uid'); })->sum('extract_price'), 'background_color'=>'layui-bg-cyan', 'col'=>4, ], [ 'name'=>'上月分销商业务佣金', 'field'=>'元', 'count'=>self::getOldDate(['data'=>'year'],UserBill::where('category','now_money')->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->where('type','brokerage'))->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>4, ], [ 'name'=>'上月分销商佣金提现金额', 'field'=>'元', 'count'=>self::getOldDate(['data'=>'year'],UserBill::where('category','now_money')->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->where('type','brokerage'))->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>4, ], ]; } /* * 分销会员 * 分销数量 饼状图 * 分销商会员访问量 曲线 * 获取购物会员人数趋势图 曲线 * 多次购物分销会员数量 饼状图 * $where array 条件 * $limit int n条数据后出拖动条 * return array */ public static function getUserDistributionChart($where,$limit=20){ //分销数量 $fenbu_user=self::getModelTime($where,new self)->field(['count(uid) as num'])->group('is_promoter')->select(); count($fenbu_user) && $fenbu_user=$fenbu_user->toArray(); $sum_user=0; $fenbu_data=[]; $fenbu_xdata=['分销商','非分销商']; $color=['#81BCFE','#91F3FE']; foreach($fenbu_user as $item){ $sum_user+=$item['num']; } foreach ($fenbu_user as $key=>$item){ $value['value']=bcdiv($item['num'],$sum_user,2)*100; $value['name']=isset($fenbu_xdata[$key]) ?$fenbu_xdata[$key].' %'.$value['value'] :''; $value['itemStyle']['color']=$color[$key]; $fenbu_data[]=$value; } //分销商会员访问量 $visit=self::getModelTime($where,self::alias('a')->join('store_visit t','t.uid=a.uid'),'t.add_time') ->where('a.is_promoter',1) ->field(['FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time','count(t.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($visit) && $visit=$visit->toArray(); $visit_data=[]; $visit_xdata=[]; $visit_zoom=''; foreach ($visit as $item){ $visit_data[]=$item['count_user']; $visit_xdata[]=$item['_add_time']; } count($visit_xdata) > $limit && $visit_zoom=$visit_xdata[$limit-5]; //获取购物会员人数趋势图 $list=self::getModelTime($where,self::where('a.status',1)->alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time') ->where(['r.paid'=>1,'a.is_promoter'=>1]) ->where('a.add_time','neq',0) ->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','count(r.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($list) && $list=$list->toArray(); $seriesdata=[]; $xdata=[]; $zoom=''; foreach ($list as $item){ $seriesdata[]=$item['count_user']; $xdata[]=$item['_add_time']; } count($xdata) > $limit && $zoom=$xdata[$limit-5]; //多次购物分销会员数量饼状图 $count=self::getModelTime($where,self::where('is_promoter',1))->count(); $user_count=self::getModelTime($where,self::alias('a') ->join('store_order r','r.uid=a.uid'),'a.add_time') ->where('a.is_promoter',1) ->where('r.paid',1) ->group('a.uid') ->count(); $shop_xdata=['多次购买数量占比','无购买数量占比']; $shop_data=[]; $count >0 && $shop_data=[ [ 'value'=>bcdiv($user_count,$count,2)*100, 'name'=>$shop_xdata[0].$user_count.'人', 'itemStyle'=>[ 'color'=>'#D789FF', ] ], [ 'value'=>bcdiv($count-$user_count,$count,2)*100, 'name'=>$shop_xdata[1].($count-$user_count).'人', 'itemStyle'=>[ 'color'=>'#7EF0FB', ] ] ]; return compact('fenbu_data','fenbu_xdata','visit_data','visit_xdata','visit_zoom','seriesdata','xdata','zoom','shop_xdata','shop_data'); } /* * 分销商佣金提现排行榜 * 分销商佣金总额排行榜 * $limit 截取条数 * return array */ public static function getUserDistributionTop10List($limit){ //分销商佣金提现排行榜 $extract=self::alias('a') ->join('user_extract t','a.uid=t.uid') ->where(['t.status'=>1,'a.is_promoter'=>1]) ->group('t.uid') ->field(['a.nickname','a.phone','sum(t.extract_price) as sum_price','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time','t.uid']) ->order('sum_price desc') ->limit($limit) ->select(); count($extract) && $extract=$extract->toArray(); //分销商佣金总额排行榜 $commission=UserBill::alias('l') ->join('user a','l.uid=a.uid') ->where(['l.status'=>'1','l.category'=>'now_money','l.type'=>'brokerage','a.is_promoter'=>1]) ->group('l.uid') ->field(['a.nickname','a.phone','sum(number) as sum_number','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time']) ->order('sum_number desc') ->limit($limit) ->select(); count($commission) && $commission=$commission->toArray(); return compact('extract','commission'); } public static function getSpreadList($uid,$page,$limit){ $list=self::where(['spread_uid'=>$uid])->field(['uid','nickname','now_money','integral','add_time']) ->order('uid desc')->page((int)$page,(int)$limit)->select(); count($list) && $list=$list->toArray(); foreach ($list as &$item){ $item['add_time']=date('Y-m-d H',$item['add_time']); } return $list; } } \ No newline at end of file + * @day: 2017/11/11 */ namespace app\admin\model\user; use app\admin\model\order\StoreOrder; use traits\ModelTrait; use app\wap\model\user\UserBill; use basic\ModelBasic; use app\admin\model\wechat\WechatUser; use app\admin\model\store\StoreCouponUser; use app\admin\model\user\UserExtract; use think\Db; /** * 用户管理 model * Class User * @package app\admin\model\user */ class User extends ModelBasic { use ModelTrait; /** * @param $where * @return array */ public static function systemPage($where){ $model = new self; if($where['status'] != '') $model = $model->where('status',$where['status']); if($where['is_promoter'] != '') $model = $model->where('is_promoter',$where['is_promoter']); if(isset($where['user_type']) && $where['user_type'] != '') $model = $model->where('user_type',$where['user_type']); if($where['nickname'] != '') $model = $model->where('nickname|uid','like',"%$where[nickname]%"); $model = $model->order('uid desc'); return self::page($model,function ($item){ if($item['spread_uid']){ $item['spread_uid_nickname'] = self::where('uid',$item['spread_uid'])->value('nickname'); }else{ $item['spread_uid_nickname'] = '无'; } },$where); } /* * 设置搜索条件 * */ public static function setWhere($where) { if($where['order']!=''){ $model=self::order(self::setOrder($where['order'])); }else{ $model=self::order('u.uid desc'); } if($where['user_time_type'] == 'visitno' && $where['user_time'] != ''){ list($startTime, $endTime) = explode(' - ', $where['user_time']); $model = $model->where('u.last_time', ['>', strtotime($endTime)+24*3600], ['<', strtotime($startTime)],'or'); } if($where['user_time_type'] == 'visit' && $where['user_time'] != ''){ list($startTime, $endTime) = explode(' - ', $where['user_time']); $model = $model->where('u.last_time', '>', strtotime($startTime)); $model = $model->where('u.last_time', '<', strtotime($endTime)+24*3600); } if($where['user_time_type'] == 'add_time' && $where['user_time'] != ''){ list($startTime, $endTime) = explode(' - ', $where['user_time']); $model = $model->where('u.add_time', '>', strtotime($startTime)); $model = $model->where('u.add_time', '<', strtotime($endTime)+24*3600); } if($where['pay_count'] !== '') { if($where['pay_count'] == '-1') $model = $model->where('pay_count',0); else $model = $model->where('pay_count','>',$where['pay_count']); } if($where['user_type'] != ''){ if($where['user_type'] == 'routine') $model = $model->where('w.routine_openid','not null'); else if($where['user_type'] == 'wechat') $model = $model->where('w.openid','not null'); } if($where['country'] != ''){ if($where['country'] == 'domestic') $model = $model->where('w.country','EQ','中国'); else if($where['country'] == 'abroad') $model = $model->where('w.country','NEQ','中国'); } return $model; } /** * 异步获取当前用户 信息 * @param $where * @return array */ public static function getUserList($where){ $model = self::setWherePage(self::setWhere($where),$where,['w.sex','w.province','w.city','u.status','u.is_promoter'],['u.nickname','u.uid']); $list = $model->alias('u') ->join('WechatUser w','u.uid=w.uid') ->field('u.*,w.country,w.province,w.city,w.sex,w.unionid,w.openid,w.routine_openid,w.groupid,w.tagid_list,w.subscribe,w.subscribe_time') ->page((int)$where['page'],(int)$where['limit']) ->select() ->each(function ($item){ $item['add_time']=date('Y-m-d H:i:s',$item['add_time']); if($item['last_time']) $item['last_time'] = date('Y-m-d H:i:s',$item['last_time']);//最近一次访问日期 else $item['last_time'] = '无访问';//最近一次访问日期 self::edit(['pay_count'=>StoreOrder::getUserCountPay($item['uid'])],$item['uid']); $item['extract_count_price'] = UserExtract::getUserCountPrice($item['uid']);//累计提现 if($item['spread_uid']){ $item['spread_uid_nickname'] = self::where('uid',$item['spread_uid'])->value('nickname').'/'.$item['spread_uid']; }else{ $item['spread_uid_nickname'] = '无'; } if($item['openid'] != '' && $item['routine_openid'] != ''){ $item['user_type']='公众号小程序类型'; }else if($item['openid'] == '' && $item['routine_openid'] != ''){ $item['user_type']='小程序类型'; }else if($item['openid'] != '' && $item['routine_openid'] == ''){ $item['user_type']='公众号类型'; }else $item['user_type']='其他类型'; if($item['sex'] == 1){ $item['sex']='男'; }else if($item['sex'] == 2){ $item['sex']='女'; }else $item['sex']='保密'; })->toArray(); $count=self::setWherePage(self::setWhere($where),$where,['w.sex','w.province','w.city','u.status','u.is_promoter'],['u.nickname','u.uid'])->alias('u')->join('WechatUser w','u.uid=w.uid')->count(); return ['count'=>$count,'data'=>$list]; } /** * 修改用户状态 * @param $uids 用户uid * @param $status 修改状态 * @return array */ public static function destrSyatus($uids,$status){ if(empty($uids) && !is_array($uids)) return false; if($status=='') return false; self::beginTrans(); try{ $res=self::where('uid','in',$uids)->update(['status'=>$status]); self::checkTrans($res); return true; }catch (\Exception $e){ self::rollbackTrans(); return Json::fail($e->getMessage()); } } /* * 获取某季度,某年某年后的时间戳 * * self::getMonth('n',1) 获取当前季度的上个季度的时间戳 * self::getMonth('n') 获取当前季度的时间戳 */ public static function getMonth($time='',$ceil=0){ if(empty($time)){ $firstday = date("Y-m-01",time()); $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day")); }else if($time=='n'){ if($ceil!=0) $season = ceil(date('n') /3)-$ceil; else $season = ceil(date('n') /3); $firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y'))); $lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y'))); }else if($time=='y'){ $firstday=date('Y-01-01'); $lastday=date('Y-12-31'); }else if($time=='h'){ $firstday = date('Y-m-d', strtotime('this week +'.$ceil.' day')) . ' 00:00:00'; $lastday = date('Y-m-d', strtotime('this week +'.($ceil+1).' day')) . ' 23:59:59'; } return array($firstday,$lastday); } public static function getcount(){ return self::count(); } /* *获取用户某个时间段的消费信息 * * reutrn Array || number */ public static function consume($where,$status='',$keep=''){ $model = new self; $user_id=[]; if(is_array($where)){ if($where['is_promoter']!='') $model=$model->where('is_promoter',$where['is_promoter']); if($where['status']!='') $model=$model->where('status',$where['status']); switch ($where['date']){ case null:case 'today':case 'week':case 'year': if($where['date']==null){ $where['date']='month'; } if($keep){ $model=$model->whereTime('add_time',$where['date'])->whereTime('last_time',$where['date']); }else{ $model=$model->whereTime('add_time',$where['date']); } break; case 'quarter': $quarter=self::getMonth('n'); $startTime=strtotime($quarter[0]); $endTime=strtotime($quarter[1]); if($keep){ $model = $model->where('add_time','>',$startTime)->where('add_time','<',$endTime)->where('last_time','>',$startTime)->where('last_time','<',$endTime); }else{ $model = $model->where('add_time','>',$startTime)->where('add_time','<',$endTime); } break; default: //自定义时间 if(strstr($where['date'],'-')!==FALSE){ list($startTime,$endTime)=explode('-',$where['date']); $model = $model->where('add_time','>',strtotime($startTime))->where('add_time','<',strtotime($endTime)); }else{ $model=$model->whereTime('add_time','month'); } break; } }else{ if(is_array($status)){ $model=$model->where('add_time','>',$status[0])->where('add_time','<',$status[1]); } } if($keep===true){ return $model->count(); } if($status==='default'){ return $model->group('from_unixtime(add_time,\'%Y-%m-%d\')')->field('count(uid) num,from_unixtime(add_time,\'%Y-%m-%d\') add_time,uid')->select()->toArray(); } if($status==='grouping'){ return $model->group('user_type')->field('user_type')->select()->toArray(); } $uid=$model->field('uid')->select()->toArray(); foreach ($uid as $val){ $user_id[]=$val['uid']; } if(empty($user_id)){ $user_id=[0]; } if($status==='xiaofei'){ $list=UserBill::where('uid','in',$user_id) ->group('type') ->field('sum(number) as top_number,title') ->select() ->toArray(); $series=[ 'name'=>isset($list[0]['title'])?$list[0]['title']:'', 'type'=>'pie', 'radius'=> ['40%', '50%'], 'data'=>[] ]; foreach($list as $key=>$val){ $series['data'][$key]['value']=$val['top_number']; $series['data'][$key]['name']=$val['title']; } return $series; }else if($status==='form'){ $list=WechatUser::where('uid','in',$user_id)->group('city')->field('count(city) as top_city,city')->limit(0,10)->select()->toArray(); $count=self::getcount(); $option=[ 'legend_date'=>[], 'series_date'=>[] ]; foreach($list as $key=>$val){ $num=$count!=0?(bcdiv($val['top_city'],$count,2))*100:0; $t=['name'=>$num.'% '.(empty($val['city'])?'未知':$val['city']),'icon'=>'circle']; $option['legend_date'][$key]=$t; $option['series_date'][$key]=['value'=>$num,'name'=>$t['name']]; } return $option; }else{ $number=UserBill::where('uid','in',$user_id)->where('type','pay_product')->sum('number'); return $number; } } /* * 获取 用户某个时间段的钱数或者TOP20排行 * * return Array || number */ public static function getUserSpend($date,$status=''){ $model=new self(); $model=$model->alias('A'); switch ($date){ case null:case 'today':case 'week':case 'year': if($date==null) $date='month'; $model=$model->whereTime('A.add_time',$date); break; case 'quarter': list($startTime,$endTime)=User::getMonth('n'); $model = $model->where('A.add_time','>',strtotime($startTime)); $model = $model->where('A.add_time','<',strtotime($endTime)); break; default: list($startTime,$endTime)=explode('-',$date); $model = $model->where('A.add_time','>',strtotime($startTime)); $model = $model->where('A.add_time','<',strtotime($endTime)); break; } if($status===true){ return $model->join('user_bill B','B.uid=A.uid')->where('B.type','pay_product')->where('B.pm',0)->sum('B.number'); } $list=$model->join('user_bill B','B.uid=A.uid') ->where('B.type','pay_product') ->where('B.pm',0) ->field('sum(B.number) as totel_number,A.nickname,A.avatar,A.now_money,A.uid,A.add_time') ->order('totel_number desc') ->limit(0,20) ->select() ->toArray(); if(!isset($list[0]['totel_number'])){ $list=[]; } return $list; } /* * 获取 相对于上月或者其他的数据 * * return Array */ public static function getPostNumber($date,$status=false,$field='A.add_time',$t='消费'){ $model=new self(); if(!$status) $model=$model->alias('A'); switch ($date){ case null:case 'today':case 'week':case 'year': if($date==null) { $date='last month'; $title='相比上月用户'.$t.'增长'; } if($date=='today') { $date='yesterday'; $title='相比昨天用户'.$t.'增长'; } if($date=='week') { $date='last week'; $title='相比上周用户'.$t.'增长'; } if($date=='year') { $date='last year'; $title='相比去年用户'.$t.'增长'; } $model=$model->whereTime($field,$date); break; case 'quarter': $title='相比上季度用户'.$t.'增长'; list($startTime,$endTime)=User::getMonth('n',1); $model = $model->where($field,'>',$startTime); $model = $model->where($field,'<',$endTime); break; default: list($startTime,$endTime)=explode('-',$date); $title='相比'.$startTime.'-'.$endTime.'时间段用户'.$t.'增长'; $Time=strtotime($endTime)-strtotime($startTime); $model = $model->where($field,'>',strtotime($startTime)+$Time); $model = $model->where($field,'<',strtotime($endTime)+$Time); break; } if($status){ return [$model->count(),$title]; } $number=$model->join('user_bill B','B.uid=A.uid')->where('B.type','pay_product')->where('B.pm',0)->sum('B.number'); return [$number,$title]; } //获取用户新增,头部信息 public static function getBadgeList($where){ $user_count=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])->count(); $user_count_old=self::getOldDate($where)->count(); $fenxiao=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])->where('spread_uid','<>',0)->count(); $fenxiao_count=self::getOldDate($where)->where('spread_uid','neq',0)->count(); $newFemxiao_count=bcsub($fenxiao,$fenxiao_count,0); $order_count=bcsub($user_count,$user_count_old,0); return [ [ 'name'=>'会员人数', 'field'=>'个', 'count'=>$user_count, 'content'=>'会员总人数', 'background_color'=>'layui-bg-blue', 'sum'=>self::count(), 'class'=>'fa fa-bar-chart', ], [ 'name'=>'会员增长', 'field'=>'个', 'count'=>$order_count, 'content'=>'会员增长率', 'background_color'=>'layui-bg-cyan', 'sum'=>$user_count_old ? bcdiv($order_count,$user_count_old,2)*100:0, 'class'=>'fa fa-line-chart', ], [ 'name'=>'分销人数', 'field'=>'个', 'count'=>$fenxiao, 'content'=>'分销总人数', 'background_color'=>'layui-bg-green', 'sum'=>self::where('spread_uid','neq',0)->count(), 'class'=>'fa fa-bar-chart', ], [ 'name'=>'分销增长', 'field'=>'个', 'count'=>$newFemxiao_count, 'content'=>'分销总人数', 'background_color'=>'layui-bg-orange', 'sum'=>$fenxiao_count ? bcdiv($newFemxiao_count,$fenxiao_count,2)*100:0, 'class'=>'fa fa-cube', ], ]; } /* * 获取会员增长曲线图和分布图 * $where 查询条件 * $limit 显示条数,是否有滚动条 */ public static function getUserChartList($where,$limit=20){ $list=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status']) ->where('add_time','neq',0) ->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','count(uid) as num']) ->order('_add_time asc') ->group('_add_time') ->select(); count($list) && $list=$list->toArray(); $seriesdata=[]; $xdata=[]; $Zoom=''; foreach ($list as $item){ $seriesdata[]=$item['num']; $xdata[]=$item['_add_time']; } (count($xdata) > $limit) && $Zoom=$xdata[$limit-5]; //多次购物会员数量饼状图 $count=self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter'])->count(); $user_count=self::setWherePage(self::getModelTime($where,self::alias('a')->join('__STORE_ORDER__ r','r.uid=a.uid'),'a.add_time'),$where,['is_promoter']) ->where('r.paid',1)->count('a.uid'); $shop_xdata=['多次购买数量占比','无购买数量占比']; $shop_data=[]; $count >0 && $shop_data=[ [ 'value'=>bcdiv($user_count,$count,2)*100, 'name'=>$shop_xdata[0], 'itemStyle'=>[ 'color'=>'#D789FF', ] ], [ 'value'=>bcdiv($count-$user_count,$count,2)*100, 'name'=>$shop_xdata[1], 'itemStyle'=>[ 'color'=>'#7EF0FB', ] ] ]; return compact('shop_data','shop_xdata','fenbu_data','fenbu_xdata','seriesdata','xdata','Zoom'); } //获取$date的前一天或者其他的时间段 public static function getOldDate($where,$moedls=null){ $model=$moedls ===null ? self::setWherePage(new self(),$where,['is_promoter','status']) :$moedls; switch ($where['data']){ case 'today': $model=$model->whereTime('add_time','yesterday'); break; case 'week': $model=$model->whereTime('add_time','last week'); break; case 'month': $model=$model->whereTime('add_time','last month'); break; case 'year': $model=$model->whereTime('add_time','last year'); break; case 'quarter': $time=self::getMonth('n',1); $model=$model->where('add_time','between',$time); break; } return $model; } //获取用户属性和性别分布图 public static function getEchartsData($where){ $model=self::alias('a'); $data=self::getModelTime($where,$model,'a.add_time') ->join('wechat_user r','r.uid=a.uid') ->group('r.province') ->field('count(r.province) as count,province') ->order('count desc') ->limit(15) ->select(); if(count($data)) $data=$data->toArray(); $legdata=[]; $dataList=[]; foreach ($data as $value){ $value['province']=='' && $value['province']='未知省份'; $legdata[]=$value['province']; $dataList[]=$value['count']; } $model=self::alias('a'); $sex=self::getModelTime($where,$model,'a.add_time') ->join('wechat_user r','r.uid=a.uid') ->group('r.sex') ->field('count(r.uid) as count,sex') ->order('count desc') ->select(); if(count($sex)) $sex=$sex->toArray(); $sexlegdata=['男','女','未知']; $sexcount=self::getModelTime($where,new self())->count(); $sexList=[]; $color=['#FB7773','#81BCFE','#91F3FE']; foreach ($sex as $key=>$item){ if($item['sex']==1){ $item_date['name']='男'; }else if($item['sex']==2){ $item_date['name']='女'; }else{ $item_date['name']='未知性别'; } $item_date['value']=bcdiv($item['count'],$sexcount,2)*100; $item_date['itemStyle']['color']=$color[$key]; $sexList[]=$item_date; } return compact('sexList','sexlegdata','legdata','dataList'); } //获取佣金记录列表 public static function getCommissionList($where){ $list=self::setCommissionWhere($where) ->page((int)$where['page'],(int)$where['limit']) ->select(); count($list) && $list=$list->toArray(); foreach ($list as &$value){ $value['ex_price']= Db::name('user_extract')->where(['uid'=>$value['uid']])->sum('extract_price'); $value['extract_price']= Db::name('user_extract')->where(['uid'=>$value['uid'],'status'=>1])->sum('extract_price'); } $count=self::setCommissionWhere($where)->count(); return ['data'=>$list,'count'=>$count]; } //获取佣金记录列表的查询条件 public static function setCommissionWhere($where){ $models=self::setWherePage(self::alias('A'),$where,[],['A.nickname','A.uid']) ->join('user_bill B','B.uid=A.uid') ->group('A.uid') ->where(['B.category'=>'now_money','B.type'=>'brokerage']) ->field(['sum(B.number) as sum_number','A.nickname','A.uid','A.now_money']); if($where['order']==''){ $models=$models->order('sum_number desc'); }else{ $models=$models->order($where['order']==1 ? 'sum_number desc':'sum_number asc'); } if($where['price_max']!='' && $where['price_min']!=''){ $models=$models->where('now_money','between',[$where['price_max'],$where['price_min']]); } return $models; } //获取某人用户推广信息 public static function getUserinfo($uid){ $userinfo=self::where(['uid'=>$uid])->field(['nickname','spread_uid','now_money','add_time'])->find()->toArray(); $userinfo['number']=UserBill::where(['category'=>'now_money','type'=>'brokerage'])->sum('number'); $userinfo['spread_name']=$userinfo['spread_uid'] ? self::where(['uid'=>$userinfo['spread_uid']])->value('nickname') :''; return $userinfo; } //获取某用户的详细信息 public static function getUserDetailed($uid){ $key_field=['real_name','phone','province','city','district','detail','post_code']; $Address=($thisAddress= Db::name('user_address')->where(['uid'=>$uid,'is_default'=>1])->field($key_field)->find()) ? $thisAddress : Db::name('user_address')->where(['uid'=>$uid])->field($key_field)->find(); $UserInfo=self::get($uid); return [ ['col'=>12,'name'=>'默认收货地址','value'=>$thisAddress ? '收货人:'.$thisAddress['real_name'].'邮编:'.$thisAddress['post_code'].' 收货人电话:'.$thisAddress['phone'].' 地址:'.$thisAddress['province'].' '.$thisAddress['city'].' '.$thisAddress['district'].' '.$thisAddress['detail'] : ''], // ['name'=>'微信OpenID','value'=>WechatUser::where(['uid'=>$uid])->value('openid'),'col'=>8], ['name'=>'手机号码','value'=>$UserInfo['phone']], // ['name'=>'ID','value'=>$uid], ['name'=>'姓名','value'=>''], ['name'=>'微信昵称','value'=>$UserInfo['nickname']], ['name'=>'邮箱','value'=>''], ['name'=>'生日','value'=>''], ['name'=>'积分','value'=>UserBill::where(['category'=>'integral','uid'=>$uid])->where('type','in',['sign','system_add'])->sum('number')], ['name'=>'上级推广人','value'=>$UserInfo['spread_uid'] ? self::where(['uid'=>$UserInfo['spread_uid']])->value('nickname'):''], ['name'=>'账户余额','value'=>$UserInfo['now_money']], ['name'=>'佣金总收入','value'=>UserBill::where(['category'=>'now_money','type'=>'brokerage','uid'=>$uid])->sum('number')], ['name'=>'提现总金额','value'=> Db::name('user_extract')->where(['uid'=>$uid,'status'=>1])->sum('extract_price')], ]; } //获取某用户的订单个数,消费明细 public static function getHeaderList($uid){ return [ [ 'title'=>'总计订单', 'value'=>StoreOrder::where(['uid'=>$uid])->count(), 'key'=>'笔', 'class'=>'', ], [ 'title'=>'总消费金额', 'value'=>StoreOrder::where(['uid'=>$uid,'paid'=>1])->sum('total_price'), 'key'=>'元', 'class'=>'', ], [ 'title'=>'本月订单', 'value'=>StoreOrder::where(['uid'=>$uid])->whereTime('add_time','month')->count(), 'key'=>'笔', 'class'=>'', ], [ 'title'=>'本月消费金额', 'value'=>StoreOrder::where(['uid'=>$uid])->whereTime('add_time','month')->sum('total_price'), 'key'=>'元', 'class'=>'', ] ]; } /* * 获取 会员 订单个数,积分明细,优惠劵明细 * * $uid 用户id; * * return array */ public static function getCountInfo($uid){ $order_count=StoreOrder::where(['uid'=>$uid])->count(); $integral_count=UserBill::where(['uid'=>$uid,'category'=>'integral'])->where('type','in',['deduction','system_add'])->count(); $sign_count=UserBill::where(['uid'=>$uid,'category'=>'integral','type'=>'sign'])->count(); $balanceChang_count=UserBill::where(['uid'=>$uid,'category'=>'now_money']) ->where('type','in',['system_add','pay_product','extract','pay_product_refund','system_sub']) ->count(); $coupon_count=StoreCouponUser::where(['uid'=>$uid])->count(); $spread_count=self::where(['spread_uid'=>$uid])->count(); return compact('order_count','integral_count','sign_count','balanceChang_count','coupon_count','spread_count'); } /* * 获取 会员业务的 * 购物会员统计 * 会员访问量 * * 曲线图 * * $where 查询条件 * * return array */ public static function getUserBusinessChart($where,$limit=20){ //获取购物会员人数趋势图 $list=self::getModelTime($where,self::where('a.status',1)->alias('a')->join('__STORE_ORDER__ r','r.uid=a.uid'),'a.add_time') ->where(['r.paid'=>1,'a.is_promoter'=>0]) ->where('a.add_time','neq',0) ->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','count(r.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($list) && $list=$list->toArray(); $seriesdata=[]; $xdata=[]; $zoom=''; foreach ($list as $item){ $seriesdata[]=$item['count_user']; $xdata[]=$item['_add_time']; } count($xdata) > $limit && $zoom=$xdata[$limit-5]; //会员访问量 $visit=self::getModelTime($where,self::alias('a')->join('__STORE_VISIT__ t','t.uid=a.uid'),'t.add_time') ->where('a.is_promoter',0) ->field(['FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time','count(t.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($visit) && $visit=$visit->toArray(); $visit_data=[]; $visit_xdata=[]; $visit_zoom=''; foreach ($visit as $item){ $visit_data[]=$item['count_user']; $visit_xdata[]=$item['_add_time']; } count($visit_xdata) > $limit && $visit_zoom=$visit_xdata[$limit-5]; //多次购物会员数量饼状图 $count=self::getModelTime($where,self::where('is_promoter',0))->count(); $user_count=self::getModelTime($where,self::alias('a')->join('__STORE_ORDER__ r','r.uid=a.uid'),'a.add_time') ->where('a.is_promoter',0) ->where('r.paid',1) ->group('a.uid') ->count(); $shop_xdata=['多次购买数量占比','无购买数量占比']; $shop_data=[]; $count >0 && $shop_data=[ [ 'value'=>bcdiv($user_count,$count,2)*100, 'name'=>$shop_xdata[0], 'itemStyle'=>[ 'color'=>'#D789FF', ] ], [ 'value'=>bcdiv($count-$user_count,$count,2)*100, 'name'=>$shop_xdata[1], 'itemStyle'=>[ 'color'=>'#7EF0FB', ] ] ]; return compact('seriesdata','xdata','zoom','visit_data','visit_xdata','visit_zoom','shop_data','shop_xdata'); } /* * 获取用户 * 积分排行 * 会员余额排行榜 * 分销商佣金总额排行榜 * 购物笔数排行榜 * 购物金额排行榜 * 分销商佣金提现排行榜 * 上月消费排行榜 * $limit 查询多少条 * return array */ public static function getUserTop10List($limit=10,$is_promoter=0){ //积分排行 $integral=self::where('status',1) ->where('is_promoter',$is_promoter) ->order('integral desc') ->field(['nickname','phone','integral','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time']) ->limit($limit) ->select(); count($integral) && $integral=$integral->toArray(); //会员余额排行榜 $now_money=self::where('status',1) ->where('is_promoter',$is_promoter) ->order('now_money desc') ->field(['nickname','phone','now_money','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time']) ->limit($limit) ->select(); count($now_money) && $now_money=$now_money->toArray(); //购物笔数排行榜 $shopcount=self::alias('a') ->join('__STORE_ORDER__ r','r.uid=a.uid') ->where(['r.paid'=>1,'a.is_promoter'=>$is_promoter]) ->group('r.uid') ->field(['a.nickname','a.phone','count(r.uid) as sum_count','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time']) ->order('sum_count desc') ->limit($limit) ->select(); count($shopcount) && $shopcount=$shopcount->toArray(); //购物金额排行榜 $order=self::alias('a') ->join('__STORE_ORDER__ r','r.uid=a.uid') ->where(['r.paid'=>1,'a.is_promoter'=>$is_promoter]) ->group('r.uid') ->field(['a.nickname','a.phone','sum(r.pay_price) as sum_price','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time','r.uid']) ->order('sum_price desc') ->limit($limit) ->select(); count($order) && $order=$order->toArray(); //上月消费排行 $lastorder=self::alias('a') ->join('__STORE_ORDER__ r','r.uid=a.uid') ->where(['r.paid'=>1,'a.is_promoter'=>$is_promoter]) ->whereTime('r.pay_time','last month') ->group('r.uid') ->field(['a.nickname','a.phone','sum(r.pay_price) as sum_price','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time','r.uid']) ->order('sum_price desc') ->limit($limit) ->select(); return compact('integral','now_money','shopcount','order','lastorder'); } /* * 获取 会员业务 * 会员总余额 会员总积分 * $where 查询条件 * * return array */ public static function getUserBusinesHeade($where){ return [ [ 'name'=>'会员总余额', 'field'=>'元', 'count'=>self::getModelTime($where,self::where('status',1))->sum('now_money'), 'background_color'=>'layui-bg-cyan', 'col'=>6, ], [ 'name'=>'会员总积分', 'field'=>'分', 'count'=>self::getModelTime($where,self::where('status',1))->sum('integral'), 'background_color'=>'layui-bg-cyan', 'col'=>6 ] ]; } /* * 分销会员头部信息查询获取 * * 分销商总佣金余额 * 分销商总提现佣金 * 本月分销商业务佣金 * 本月分销商佣金提现金额 * 上月分销商业务佣金 * 上月分销商佣金提现金额 * $where array 时间条件 * * return array */ public static function getDistributionBadgeList($where){ return [ [ 'name'=>'分销商总佣金', 'field'=>'元', 'count'=>self::getModelTime($where,UserBill::where('category','now_money')->where('type','brokerage'))->where('uid','in',function($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'分销商总佣金余额', 'field'=>'元', 'count'=>self::getModelTime($where,self::where('status',1)->where('is_promoter',1))->sum('now_money'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'分销商总提现佣金', 'field'=>'元', 'count'=>self::getModelTime($where,UserExtract::where('status',1))->sum('extract_price'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'本月分销商业务佣金', 'field'=>'元', 'count'=>self::getModelTime(['data'=>'month'],UserBill::where('category','now_money')->where('type','brokerage')) ->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>3, ], [ 'name'=>'本月分销商佣金提现金额', 'field'=>'元', 'count'=>self::getModelTime(['data'=>'month'],UserExtract::where('status',1)) ->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->field('uid'); })->sum('extract_price'), 'background_color'=>'layui-bg-cyan', 'col'=>4, ], [ 'name'=>'上月分销商业务佣金', 'field'=>'元', 'count'=>self::getOldDate(['data'=>'year'],UserBill::where('category','now_money')->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->where('type','brokerage'))->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>4, ], [ 'name'=>'上月分销商佣金提现金额', 'field'=>'元', 'count'=>self::getOldDate(['data'=>'year'],UserBill::where('category','now_money')->where('uid','in',function ($query){ $query->name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','neq',0)->field('uid'); })->where('type','brokerage'))->sum('number'), 'background_color'=>'layui-bg-cyan', 'col'=>4, ], ]; } /* * 分销会员 * 分销数量 饼状图 * 分销商会员访问量 曲线 * 获取购物会员人数趋势图 曲线 * 多次购物分销会员数量 饼状图 * $where array 条件 * $limit int n条数据后出拖动条 * return array */ public static function getUserDistributionChart($where,$limit=20){ //分销数量 $fenbu_user=self::getModelTime($where,new self)->field(['count(uid) as num'])->group('is_promoter')->select(); count($fenbu_user) && $fenbu_user=$fenbu_user->toArray(); $sum_user=0; $fenbu_data=[]; $fenbu_xdata=['分销商','非分销商']; $color=['#81BCFE','#91F3FE']; foreach($fenbu_user as $item){ $sum_user+=$item['num']; } foreach ($fenbu_user as $key=>$item){ $value['value']=bcdiv($item['num'],$sum_user,2)*100; $value['name']=isset($fenbu_xdata[$key]) ?$fenbu_xdata[$key].' %'.$value['value'] :''; $value['itemStyle']['color']=$color[$key]; $fenbu_data[]=$value; } //分销商会员访问量 $visit=self::getModelTime($where,self::alias('a')->join('__STORE_VISIT__ t','t.uid=a.uid'),'t.add_time') ->where('a.is_promoter',1) ->field(['FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time','count(t.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($visit) && $visit=$visit->toArray(); $visit_data=[]; $visit_xdata=[]; $visit_zoom=''; foreach ($visit as $item){ $visit_data[]=$item['count_user']; $visit_xdata[]=$item['_add_time']; } count($visit_xdata) > $limit && $visit_zoom=$visit_xdata[$limit-5]; //获取购物会员人数趋势图 $list=self::getModelTime($where,self::where('a.status',1)->alias('a')->join('__STORE_ORDER__ r','r.uid=a.uid'),'a.add_time') ->where(['r.paid'=>1,'a.is_promoter'=>1]) ->where('a.add_time','neq',0) ->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','count(r.uid) as count_user']) ->group('_add_time') ->order('_add_time asc') ->select(); count($list) && $list=$list->toArray(); $seriesdata=[]; $xdata=[]; $zoom=''; foreach ($list as $item){ $seriesdata[]=$item['count_user']; $xdata[]=$item['_add_time']; } count($xdata) > $limit && $zoom=$xdata[$limit-5]; //多次购物分销会员数量饼状图 $count=self::getModelTime($where,self::where('is_promoter',1))->count(); $user_count=self::getModelTime($where,self::alias('a') ->join('__STORE_ORDER__ r','r.uid=a.uid'),'a.add_time') ->where('a.is_promoter',1) ->where('r.paid',1) ->group('a.uid') ->count(); $shop_xdata=['多次购买数量占比','无购买数量占比']; $shop_data=[]; $count >0 && $shop_data=[ [ 'value'=>bcdiv($user_count,$count,2)*100, 'name'=>$shop_xdata[0].$user_count.'人', 'itemStyle'=>[ 'color'=>'#D789FF', ] ], [ 'value'=>bcdiv($count-$user_count,$count,2)*100, 'name'=>$shop_xdata[1].($count-$user_count).'人', 'itemStyle'=>[ 'color'=>'#7EF0FB', ] ] ]; return compact('fenbu_data','fenbu_xdata','visit_data','visit_xdata','visit_zoom','seriesdata','xdata','zoom','shop_xdata','shop_data'); } /* * 分销商佣金提现排行榜 * 分销商佣金总额排行榜 * $limit 截取条数 * return array */ public static function getUserDistributionTop10List($limit){ //分销商佣金提现排行榜 $extract=self::alias('a') ->join('user_extract t','a.uid=t.uid') ->where(['t.status'=>1,'a.is_promoter'=>1]) ->group('t.uid') ->field(['a.nickname','a.phone','sum(t.extract_price) as sum_price','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time','t.uid']) ->order('sum_price desc') ->limit($limit) ->select(); count($extract) && $extract=$extract->toArray(); //分销商佣金总额排行榜 $commission=UserBill::alias('l') ->join('user a','l.uid=a.uid') ->where(['l.status'=>'1','l.category'=>'now_money','l.type'=>'brokerage','a.is_promoter'=>1]) ->group('l.uid') ->field(['a.nickname','a.phone','sum(number) as sum_number','FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time']) ->order('sum_number desc') ->limit($limit) ->select(); count($commission) && $commission=$commission->toArray(); return compact('extract','commission'); } public static function getSpreadList($uid,$page,$limit){ $list=self::where(['spread_uid'=>$uid])->field(['uid','nickname','now_money','integral','add_time']) ->order('uid desc')->page((int)$page,(int)$limit)->select(); count($list) && $list=$list->toArray(); foreach ($list as &$item){ $item['add_time']=date('Y-m-d H',$item['add_time']); } return $list; } } \ No newline at end of file diff --git a/application/routine/model/routine/RoutineServer.php b/application/routine/model/routine/RoutineServer.php index 82ffc302..f0d6a037 100644 --- a/application/routine/model/routine/RoutineServer.php +++ b/application/routine/model/routine/RoutineServer.php @@ -2,7 +2,7 @@ namespace app\routine\model\routine; use app\admin\model\system\SystemConfig; - +use think\Db; class RoutineServer{ /** * curl get方式 @@ -73,14 +73,14 @@ class RoutineServer{ * @return mixed */ public static function get_access_token(){ - $accessToken = db('routine_access_token')->where('id',1)->find(); + $accessToken = Db::name('routine_access_token')->where('id',1)->find(); if($accessToken['stop_time'] > time()) return $accessToken['access_token']; else{ $accessToken = self::getAccessToken(); if(isset($accessToken['access_token'])){ $data['access_token'] = $accessToken['access_token']; $data['stop_time'] = bcadd($accessToken['expires_in'],time(),0); - db('routine_access_token')->where('id',1)->update($data); + Db::name('routine_access_token')->where('id',1)->update($data); } return $accessToken['access_token']; }