<?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;
|
}
|
|
}
|