liyaozhi
2025-10-29 52b7c373601edbc5010471082eb88dadf70e382d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
 
namespace app\agent\model;
 
use app\agent\model\page\Page as PageModel;
use app\common\model\agent\Client as ClientModel;
 
class Client extends ClientModel
{
    /**
     * 获取小程序列表
     */
    public function getList($limit, $is_recycle = false)
    {
        $agent_id=self::$agent_id;
        return $this->alias('client')->field(['client.*,agent.agent_name'])->where('client.is_recycle', '=', (int)$is_recycle)
            ->join('dl_agent agent', 'agent.agent_id = client.agent_id','left')
            ->with(['app','shopuser','role','roleaccess'])
            ->where('client.agent_id', '=', $agent_id)
            ->where('client.is_delete', '=', 0)
            ->order(['client.create_time' => 'asc'])
            ->paginate($limit);
    }
 
    /**
     * 新增记录
     */
    public function add($data)
    {
        $this->startTrans();
        try {
            // 添加小程序记录
            $data['agent_id']=self::$agent_id;
            $this->save($data);
           
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
 
    /**
     * 修改记录
     */
    public function edit($data)
    {
        $this->startTrans();
        try {
            $save_data = [
                'client_name' => $data['client_name'],
                'company' => $data['company'],
                'mark_manager' => $data['mark_manager'],
                'handrate_wx'=>$data['handrate_wx'],
                'commissionrate_wx' => $data['commissionrate_wx']
            ];
            $this->save($save_data);
            
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
    /**
     * 移入移出回收站
     */
    public function recycle($is_recycle = true)
    {
        return $this->save(['is_recycle' => (int)$is_recycle]);
    }
 
    /**
     * 软删除
     */
    public function setDelete()
    {
        return $this->save(['is_delete' => 1]);
    }
    
    //获取客户总数
    public function getClinetTotal($agent_id){
        $list = $this->where('agent_id','=',$agent_id)->where('is_delete', '=', 0)->select();
        //dd($agent_id);
        return count($list);
    }
    //获取客户今日昨日新增1634279501
    public function getClinetByDay($agent_id){
        $arr = [];
        $today = strtotime(date('Y-m-d'));
 
        $tday = $this->where('agent_id','=',$agent_id)
                    ->where('is_delete', '=', 0)
                    ->where('create_time', '>=', $today)
                    ->select();
                    
        $ytd = $this->where('agent_id','=',$agent_id)
                    ->where('is_delete', '=', 0)
                    ->where('create_time', '<', $today)
                    ->where('create_time', '>=', $today - 86400)
                    ->select();
 
        $arr['tday'] = number_format(count($tday));
        $arr['ytd'] = number_format(count($ytd));
        return $arr;
    }
 
}