repository = $repository; } /** * Common: 兑换码列表 * Author: wu-hui * Time: 2024/03/02 14:21 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getList(){ [$page, $limit] = $this->getPage(); $params = $this->request->params(['is_export','batch_unique','status','mer_id','staff_id','group_data_id']); $params['mer_id'] = $this->request->merId(); $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); // 导出数据处理 if($params['is_export'] == 1){ // 处理其他导出信息 $data['title'] = [ '兑换码', '生成时间:' . date('Y-m-d H:i:s',time()) ]; // $data['header'] = ['批次名称','批次编号','兑换码', '小程序链接']; $data['header'] = ['批次名称','批次编号','兑换码']; $data['filename'] = '兑换码_'.time(); // 处理跳转路径 $data['list'] = array_map(function($item){ // $path = '/pages/annex/vip_center/index?ec='.$item['exchange_code']; return [ $item['batch_title'] ?? '', $item['batch_unique'] ?? '', $item['exchange_code'] // $path, ]; }, $data['list']); $data['list'] = array_reverse($data['list']); } return app('json')->success($data); } /** * Common: 获取批次列表 * Author: wu-hui * Time: 2024/03/02 14:45 * @return mixed */ public function getBatchList(){ $params['mer_id'] = $this->request->merId(); $list = $this->repository->getSearchModel($params)->column('batch_unique','batch_title'); return app('json')->success($list); } /** * Common: 兑换码编辑表单 * Author: wu-hui * Time: 2024/03/02 11:39 * @return mixed * @throws \FormBuilder\Exception\FormBuilderException */ public function editForm(){ $data = $this->repository->getEditFormData(); return app('json')->success(formToData($data)); } /** * Common: 兑换码编辑提交信息 * Author: wu-hui * Time: 2024/03/02 14:07 * @return mixed */ public function editInfo(){ $params = $this->request->params([ ['type', 0], 'prefix', ['start', 0], ['end', 0], 'batch_title', ['create_num', 0] ]); $this->repository->createExchangeCode($params); return app('json')->success('添加成功'); } /** * Common: 分配商户 || 分配给员工 * Author: wu-hui * Time: 2024/03/02 16:51 * @return mixed * @throws \FormBuilder\Exception\FormBuilderException */ public function activateForm(){ $merId = $this->request->merId(); if($merId > 0){ // 商户操作 - 分配给员工并且激活 $data = $this->repository->getActivateFormData($merId); }else{ // 总平台操作 - 分配给商户 $data = $this->repository->allocationMerchantFormData(); } return app('json')->success(formToData($data)); } /** * Common: 提交表单 * Author: wu-hui * Time: 2024/03/02 16:56 * @return mixed */ public function activateInfo(){ $merId = $this->request->merId(); if($merId > 0){ // 商户操作 - 分配给员工并且激活 $params = $this->request->params(['start_id','end_id',['staff_id', 0]]); $this->repository->activateExchangeCode($params, $merId); }else{ // 总平台操作 - 分配给商户 $params = $this->request->params(['start_id','end_id',['mer_id', 0],['group_data_id',0]]); $this->repository->allocationMerchantExchangeCode($params); } return app('json')->success('激活成功'); } /** * Common: 获取搜索条件对象列表 * Author: wu-hui * Time: 2024/03/03 10:40 * @return mixed */ public function getSearchData(){ $merId = $this->request->merId(); $groupId = app()->make(GroupRepository::class)->getSearch(['group_key' => 'svip_pay'])->value('group_id'); $data['vipList'] = app()->make(GroupDataRepository::class) ->getSearch([]) ->field(['group_data_id','value']) ->withAttr('value', function ($val) { $value = json_decode($val, true); return $value['svip_name'] ?? ''; }) ->where('mer_id', 0) ->where('status', 1) ->where('group_id', $groupId) ->order('sort DESC,group_data_id ASC') ->select() ->toArray(); if($merId > 0){ // 商户操作 $data['service'] = app()->make(StoreServiceRepository::class) ->getSearch([]) ->field(['nickname','service_id']) ->where('mer_id', $merId) ->where('is_del', 0) ->select() ->toArray(); }else{ // 总平台操作 $data['mer_list'] = app()->make(MerchantRepository::class) ->search(['is_del' => 0,'merchant_type' => 0,'status' => 1]) ->field(['mer_id','mer_name']) ->select() ->toArray(); } return app('json')->success($data); } /** * Common: 兑换码作废 - 表单 * Author: wu-hui * Time: 2024/03/09 17:21 * @return mixed * @throws \FormBuilder\Exception\FormBuilderException */ public function cancelForm(){ $merId = $this->request->merId(); $data = $this->repository->cancelFormData($merId); return app('json')->success(formToData($data)); } /** * Common: 兑换码作废 - 提交表单并且进行处理 * Author: wu-hui * Time: 2024/03/09 17:25 * @return mixed */ public function cancelInfo(){ $merId = $this->request->merId(); $params = $this->request->params(['start_id','end_id']); $this->repository->cancelExchangeCode($params, $merId); return app('json')->success('作废成功'); } /** * Common: 修改兑换码 * Author: wu-hui * Time: 2024/03/30 15:45 * @return mixed */ public function updateCode(){ $params = $this->request->params(['id','new_exchange_code']); $this->repository->updateExchangeCode($params); return app('json')->success('修改成功'); } }