123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\data\controller\user;
- use app\data\model\BaseUserUpgrade;
- use app\data\model\DataUser;
- use app\data\model\DataUserRebate;
- use app\data\model\ShopOrderItem;
- use app\data\service\RebateService;
- use app\data\service\UserRebateService;
- use think\admin\Controller;
- /**
- * 用户返利管理
- * Class Rebate
- * @package app\data\controller\user
- */
- class Rebate extends Controller
- {
- /**
- * 用户返利管理
- * @auth true
- * @menu true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function index()
- {
- $this->title = '用户返利管理';
- // 统计所有返利
- $this->types = RebateService::PRIZES;
- $this->rebate = UserRebateService::amount(0);
- // 创建查询对象
- $query = DataUserRebate::mQuery()->equal('type')->like('name,order_no');
- // 会员条件查询
- $db = $this->_query('DataUser')->like('nickname#order_nickname,phone#order_phone')->db();
- if ($db->getOptions('where')) $query->whereRaw("order_uuid in {$db->field('id')->buildSql()}");
- // 代理条件查询
- $db = $this->_query('DataUser')->like('nickname#agent_nickname,phone#agent_phone')->db();
- if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
- // 查询分页
- $query->dateBetween('create_at')->order('id desc')->page();
- }
- /**
- * 商城订单列表处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- protected function _index_page_filter(array &$data)
- {
- $uids = array_merge(array_column($data, 'uuid'), array_column($data, 'order_uuid'));
- $userItem = DataUser::mk()->whereIn('id', array_unique($uids))->select();
- $goodsItem = ShopOrderItem::mk()->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select();
- foreach ($data as &$vo) {
- $vo['type'] = RebateService::name($vo['type']);
- [$vo['user'], $vo['agent'], $vo['list']] = [[], [], []];
- foreach ($userItem as $user) {
- if ($user['id'] === $vo['uuid']) $vo['agent'] = $user;
- if ($user['id'] === $vo['order_uuid']) $vo['user'] = $user;
- }
- foreach ($goodsItem as $goods) {
- if ($goods['order_no'] === $vo['order_no']) {
- $vo['list'][] = $goods;
- }
- }
- }
- }
- /**
- * 用户返利配置
- * @auth true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function config()
- {
- $this->skey = 'RebateRule';
- $this->title = '用户返利配置';
- if ($this->request->isGet()) {
- $this->data = sysdata($this->skey);
- $this->levels = BaseUserUpgrade::items();
- $this->fetch();
- } else {
- sysdata($this->skey, $this->request->post());
- $this->success('奖励修改成功');
- }
- }
- }
|