134 lines
4.0 KiB
PHP
134 lines
4.0 KiB
PHP
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\controller\merchant\user;
|
|
|
|
|
|
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
use app\common\repositories\system\merchant\MerchantRepository;
|
|
use app\common\repositories\user\UserLabelRepository;
|
|
use app\common\repositories\user\UserMerchantRepository;
|
|
use crmeb\basic\BaseController;
|
|
use FormBuilder\Exception\FormBuilderException;
|
|
use think\App;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\DbException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
|
/**
|
|
* Class UserMerchant
|
|
* @package app\controller\merchant\user
|
|
* @author xaboy
|
|
* @day 2020/10/20
|
|
*/
|
|
class UserMerchant extends BaseController
|
|
{
|
|
/**
|
|
* @var UserMerchantRepository
|
|
*/
|
|
protected $repository;
|
|
|
|
/**
|
|
* UserMerchant constructor.
|
|
* @param App $app
|
|
* @param UserMerchantRepository $repository
|
|
*/
|
|
public function __construct(App $app, UserMerchantRepository $repository)
|
|
{
|
|
parent::__construct($app);
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
/**
|
|
* @return \think\response\Json
|
|
* @author xaboy
|
|
* @day 2020/10/20
|
|
*/
|
|
public function getList(){
|
|
$isSearch = $this->request->param('is_search', 0);
|
|
$where = $this->request->params([
|
|
'nickname',
|
|
'sex',
|
|
'is_promoter',
|
|
'user_time_type',
|
|
'user_time',
|
|
'pay_count',
|
|
'label_id',
|
|
'user_type',
|
|
'uid'
|
|
]);
|
|
[$page, $limit] = $this->getPage();
|
|
$where['mer_id'] = $this->request->merId();
|
|
$where['merchant_type'] = (int)app()->make(MerchantRepository::class)->getSearch(['mer_id'=>$where['mer_id']])->value('merchant_type');
|
|
if($where['merchant_type'] != 0) {
|
|
// 非普通商户 查询所有用户;必须通过搜索
|
|
$where['mer_id'] = '';
|
|
// 判断:是否必须搜索
|
|
$data = [];
|
|
if(!empty($where['nickname']) || !empty($where['uid'])) $data = $this->repository->getList($where, $page, $limit);
|
|
}else{
|
|
$data = $this->repository->getList($where, $page, $limit);
|
|
}
|
|
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $id
|
|
* @return mixed
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws FormBuilderException
|
|
* @throws ModelNotFoundException
|
|
* @author xaboy
|
|
* @day 2020-05-08
|
|
*/
|
|
public function changeLabelForm($id)
|
|
{
|
|
if (!$this->repository->exists($id))
|
|
return app('json')->fail('数据不存在');
|
|
return app('json')->success(formToData($this->repository->changeLabelForm($this->request->merId(), $id)));
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $id
|
|
* @param UserLabelRepository $labelRepository
|
|
* @return mixed
|
|
* @throws DbException
|
|
* @author xaboy
|
|
* @day 2020-05-08
|
|
*/
|
|
public function changeLabel($id, UserLabelRepository $labelRepository)
|
|
{
|
|
$label_id = (array)$this->request->param('label_id', []);
|
|
if (!$this->repository->exists($id))
|
|
return app('json')->fail('数据不存在');
|
|
$merId = $this->request->merId();
|
|
$label_id = $labelRepository->intersection((array)$label_id, $merId, 0);
|
|
$label_id = array_unique(array_merge($label_id, $this->repository->get($id)->authLabel));
|
|
$label_id = implode(',', $label_id);
|
|
$this->repository->update($id, compact('label_id'));
|
|
return app('json')->success('修改成功');
|
|
}
|
|
|
|
public function order($uid)
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$data = app()->make(StoreOrderRepository::class)->userMerList($uid, $this->request->merId(), $page, $limit);
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
public function coupon($uid)
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$data = app()->make(StoreCouponUserRepository::class)->userList(['mer_id' => $this->request->merId(), 'uid' => (int)$uid], $page, $limit);
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
}
|