123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace app\api\controller\company;
- use app\common\controller\Apic;
- use think\Db;
- /**
- * 客户
- */
- class Customer extends Apic
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- //头部统计
- 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($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);
- }
- }
|