// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\store\controller\members; use app\common\enum\member\AuditStatus; use app\store\controller\Controller; use app\store\controller\Goods; use app\store\model\Goods as GoodsModel; use app\store\model\member\Apply as ApplyModel; use app\store\model\member\MemberGoods as MemberGoodsModel; /** * 会员价商品管理 * Class Refund * @package app\store\controller\member */ class Apply extends Controller { /** * 列表 * @return array * @throws \think\db\exception\DbException * @author: zjwhust * @Time: 2022/5/25 14:56 */ public function list() { $model = new ApplyModel; $list = $model->getList($this->request->param()); return $this->renderSuccess(compact('list')); } /** * 详情 * @param int $id * @return array; * @author: zjwhust * @Time: 2022/5/25 14:58 */ public function detail(int $id){ $detail = ApplyModel::detail($id,['applyGoods'=>['goods']]); return $this->renderSuccess(compact('detail')); } /** * 新增 * @return array * @author: zjwhust * @Time: 2022/5/25 14:56 */ public function add() { $model = new ApplyModel; $postData = $this->postForm(); $postData['number'] = 'HYJ'.date('YmdHis').rand(100,999); $postData['admin_name'] = $postData['audit_user'] = $this->store['user']['real_name']?:''; $postData['admin_id'] = $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:''; if(!$model->add($postData)){ return $this->renderError($model->getError() ?: '新增失败'); } return $this->renderSuccess([], '新增成功'); } /** * 获取新增会员价商品时的弹窗列表 * @return array * @throws \think\db\exception\DbException * @author: zjwhust * @Time: 2022/5/27 16:50 */ public function addGoodsList(){ $memberGoodsIds = (new MemberGoodsModel())->goodIds();//获取会员价商品ID集合 $applyGoodsIds = (new ApplyModel())->goodIds(); //获取会员价商品审核中的商品ID集合 $goodIds = array_unique(array_merge($memberGoodsIds,$applyGoodsIds)); // 获取列表记录 $model = new GoodsModel; $params = $this->request->param(); $params['sortType'] = 'create_time'; $params['listType'] = 'on_sale'; $params['not_goods_id_arr'] = $goodIds; $list = $model->getList($params); return $this->renderSuccess(compact('list')); } /** * 获取编辑会员价商品时的弹窗列表 * @return array * @throws \think\db\exception\DbException * @author: zjwhust * @Time: 2022/5/27 16:55 */ public function editGoodsList(){ $memberGoodsIds = (new MemberGoodsModel())->goodIds();//获取会员价商品ID集合 $applyGoodsIds = (new ApplyModel())->goodIds(); //获取会员价商品审核中的商品ID集合 $goodIds = array_unique(array_diff($memberGoodsIds,$applyGoodsIds)); // 获取列表记录 $model = new GoodsModel; $params = $this->request->param(); $params['sortType'] = 'create_time'; $params['listType'] = 'on_sale'; $params['goods_id_arr'] = $goodIds; $list = $model->getList($params); $memberGoods = MemberGoodsModel::whereIn('goods_id',$goodIds)->column('discount','goods_id'); foreach ($list as &$item){ $item['discount'] = $memberGoods[$item['goods_id']]; } return $this->renderSuccess(compact('list')); } /** * 编辑 * @return array * @author: zjwhust * @Time: 2022/5/25 16:56 */ // public function edit(int $id) // { // $postData = $this->postForm(); // $model = ApplyModel::find($id); // $postData['audit_status'] = AuditStatus::AUDIT_WAIT; // $postData['audit_user'] = $this->store['user']['real_name']?:''; // $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:''; // if(!$model->edit($postData)){ // return $this->renderError($model->getError() ?: '编辑失败'); // } // return $this->renderSuccess([], '编辑成功'); // } /** * 审核 * @return array * @author: zjwhust * @Time: 2022/5/25 14:56 */ public function audit() { $postData = $this->postForm(); $model = ApplyModel::find($postData['id']); $postData['audit_user'] = $this->store['user']['real_name']?:''; $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:''; if(!$model->audit($postData)){ return $this->renderError($model->getError() ?: '审核失败'); } return $this->renderSuccess([], '审核成功'); } /** * 删除 * @return array * @author: zjwhust * @Time: 2022/5/25 16:56 */ // public function delete() // { // $postData = $this->postForm(); // $model = ApplyModel::find($postData['id']); // $postData['audit_user'] = $this->store['user']['real_name']?:''; // $postData['audit_admin_id'] = $this->store['user']['store_user_id']?:''; // if(!$model->audit($postData)){ // return $this->renderError($model->getError() ?: '审核失败'); // } // return $this->renderSuccess([], '审核成功'); // } }