Browse Source

客户管理

lizhen_gitee 1 year ago
parent
commit
ab292eeb0d

+ 100 - 32
application/api/controller/company/Customer.php

@@ -15,18 +15,53 @@ class Customer extends Apic
 
     //头部统计
     public function index(){
-
+        $where = [
+            'company_id' => $this->auth->company_id,
+        ];
+        if($this->auth->type == 2){
+            $where['staff_id'] = $this->auth->id;
+        }
+        //全部
+        $customer_all = Db::name('user_wallet')->where($where)->count();
+        //今日
+        $starttime = strtotime(date('Y-m-d'));
+        $endtime = $starttime + 86399;
+        $where['createtime'] = ['BETWEEN',[$starttime,$endtime]];
+        $customer_today = Db::name('user_wallet')->where($where)->count();
+        //七日
+        $starttime = strtotime(date('Y-m-d')) - 518400;
+        $where['createtime'] = ['BETWEEN',[$starttime,$endtime]];
+        $customer_week = Db::name('user_wallet')->where($where)->count();
+
+        //
+        $rs = [
+            'today'=>$customer_today,
+            'week' => $customer_week,
+            'all'  => $customer_all,
+        ];
+
+        $this->success(1,$rs);
     }
 
     //列表
     public function lists(){
+        $keyword = input('keyword','');
+
+        $where = [
+            'w.company_id' => $this->auth->company_id,
+        ];
+        if(!empty($keyword)){
+            $where['user.nickname|user.mobile'] = ['LIKE','%'.$keyword.'%'];
+        }
+
         $list = Db::name('user_wallet')->alias('w')
             ->field('w.*,user.nickname,user.mobile,user.avatar')
             ->join('user','w.user_id = user.id','LEFT')
-            ->where('w.company_id',$this->auth->company_id)
+            ->where($where)
             ->order('id desc')->autopage()->select();
         $list = list_domain_image($list,['avatar']);
 
+        //追加车牌
         if(!empty($list)){
             $user_ids = array_column($list,'user_id');
             $user_car = Db::name('user_car')->where('user_id','IN',$user_ids)->select();
@@ -47,46 +82,79 @@ class Customer extends Apic
 
     //新增
     public function add(){
-        $field = ['price','giftprice'];
-        $data = request_post_hub($field);
 
-        $data['company_id'] = $this->auth->company_id;
-        $data['status'] = 1;
 
-        Db::startTrans();
-        $config_id = Db::name('recharge_config')->insertGetId($data);
-        if(!$config_id){
-            Db::rollback();
-            $this->error('添加失败');
+        $this->success('添加成功');
+    }
+
+    //余额管理
+    public function changemoney(){
+        $id = input('id',0);
+        $user_id = input('user_id',0);
+        $type = input('type',1); //1增加,2减少
+        $money = input('money',0);
+
+        $number  = $type == 1 ? $money : -$money;
+        $logtype = $type == 1 ? 101 : 102;
+
+
+        //检查
+        $map = [
+            'id' => $id,
+            'user_id' => $user_id,
+            'company_id' => $this->auth->company_id,
+        ];
+        $check = Db::name('user_wallet')->where($map)->find();
+        if(!$check){
+            $this->error('错误的客户');
         }
 
-        //赠送卡券
-        $gift_data = input('gift_data','','trim');
-        $gift_data = json_decode(htmlspecialchars_decode($gift_data),true);
-
-        if(is_array($gift_data) && !empty($gift_data)){
-            $recharge_gift = [];
-            foreach($gift_data as $key => $val){
-                $recharge_gift[] = [
-                    'config_id' => $config_id,
-                    'coupon_id' => $val['coupon_id'],
-                    'number'    => $val['number'],
-                ];
-            }
-            if(!empty($recharge_gift)){
-                $rs_gift = Db::name('recharge_gift')->insertAll($recharge_gift);
-                if($rs_gift === false){
-                    Db::rollback();
-                    $this->error('添加失败');
-                }
-            }
+        Db::startTrans();
+        $rs = model('wallet')->lockChangeAccountRemain($this->auth->company_id,$user_id,'money',$number,$logtype,$remark='门店操作余额');
+        if($rs['status'] === false){
+            Db::rollback();
+            $this->error($rs['msg']);
         }
 
         Db::commit();
+        $this->success();
+    }
 
-        $this->success('添加成功');
+    //客户详情
+    public function userinfo(){
+        $user_id = input('user_id',0);
+
+        $map = [
+            'w.user_id' => $user_id,
+            'w.company_id' => $this->auth->company_id,
+        ];
+
+        $info = Db::name('user_wallet')->alias('w')
+            ->field('w.*,user.nickname,user.mobile,user.avatar')
+            ->join('user','w.user_id = user.id','LEFT')
+            ->where($map)->find();
+
+        $info = info_domain_image($info,['avatar']);
+
+        $this->success(1,$info);
     }
 
+    //某客户消费明细
+    public function moneylog(){
+        $user_id = input('user_id',0);
+
+        $map = [
+            'user_id' => $user_id,
+            'company_id' => $this->auth->company_id,
+        ];
+
+        $list = Db::name('user_money_log')->where($map)->order('id desc')->autopage()->select();
+        foreach($list as $key => &$val){
+            $val['change_value'] = $val['change_value'] > 0 ? '+'.$val['change_value'] : $val['change_value'];
+            $val['remark'] = '['.$val['remark'].'] '.$val['change_value'].',余额'.$val['remain'];
+        }
+        $this->success(1,$list);
+    }
 
 
 

+ 1 - 1
application/api/controller/company/Recharge.php

@@ -23,7 +23,7 @@ class Recharge extends Apic
             'status'     => $status,
         ];
 
-        $list = Db::name('recharge_config')->where($where)->order('id asc')->select();
+        $list = Db::name('recharge_config')->where($where)->order('id desc')->select();
 
         //追加赠送
         if(!empty($list)){

+ 6 - 5
application/extra/wallet.php

@@ -4,13 +4,14 @@
  */
 return [
     'logtype' => [
-        1  => '后台充值',
-        2  => '扫码佣金',
-        3  => '关联佣金',
-        4  => '佣金提现',
+        //用户钱包,100开始
+        101  => '门店操作', //增加
+        102  => '门店操作', //减少
+
+        //商户钱包,200开始
     ],
     'moneyname' => [
-        'money'    => '佣金',
+        'money'    => '储值卡',
     ],
 
 ];