Files
amb_wechatapp/application/api/controller/app/agent/Customer.php
T

96 lines
2.0 KiB
PHP

<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 下级
*/
class Customer extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\api\model\app\agent\Relation();
$this->orderModel = new \app\api\model\app\agent\Order();
}
/**
* 获取下级列表
* @return void
*/
public function getCustomerList(){
$limit = input('limit',10);
$page = input('page',1);
$order = input('order','desc');
$name = input('name','');
$where = [
'parent_id'=>$this->auth->id
];
if($name){
$where['user.nickname'] = ['like',"%{$name}%"];
}
$list = $this->model
->with(['user'])
->where($where)
->limit($limit)
->page($page)
->order('relation.createtime',$order)
->select();
if(!empty($list)){
foreach ($list as $item){
$item->user->visible(['nickname','avatar','id']);
$item->order = $this->orderModel->getChildUserOrder($item->user_id);
}
}
$this->success('获取成功', $list);
}
/**
* 获取客户详情
* @return void
*/
public function getCustomerDetail(){
$userId = input('user_id');
$where = [
'parent_id'=>$this->auth->id,
'user_id'=>$userId
];
$detail = $this->model
->with(['user'])
->where($where)
->find();
if(!$detail){
$this->error('暂时无法查看,请刷新重试');
}
$detail->user->visible(['nickname','avatar','id']);
$detail['order'] = $this->orderModel->getChildUserOrder($userId);
$this->success('获取成功', $detail);
}
}