$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($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(); foreach($list as $key => &$val){ $val['car_number'] = ''; $car_number = []; foreach($user_car as $k => $v){ if($val['user_id'] == $v['user_id']){ $car_number[] = $v['car_number']; } $val['car_number'] = implode(',',$car_number); } } } $this->success(1,$list); } //新增 public function add(){ $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('错误的客户'); } 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(); } //客户详情 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); } }