repository = $repository; } /** * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020-04-16 */ public function lst() { [$page, $limit] = $this->getPage(); $where = $this->request->params(['keyword', 'date', 'status','mer_state','city', 'account']); return app('json')->success($this->repository->lstLeft($where, $page, $limit)); // return app('json')->success($this->repository->lst($where, $page, $limit)); } /** * @return mixed * @throws FormBuilderException * @author xaboy * @day 2020-04-16 */ public function createForm() { return app('json')->success(formToData($this->repository->form())); } /** * @param MerchantValidate $validate * @param MerchantCategoryRepository $merchantCategoryRepository * @param MerchantAdminRepository $adminRepository * @return mixed * @author xaboy * @day 2020/7/2 */ public function create(MerchantValidate $validate, MerchantCategoryRepository $merchantCategoryRepository, MerchantAdminRepository $adminRepository) { $data = $this->checkParam($validate); if ($this->repository->fieldExists('mer_name', $data['mer_name'])) return app('json')->fail('商户名已存在'); if ($data['mer_phone'] && isPhone($data['mer_phone'])) return app('json')->fail('请输入正确的手机号'); if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id'])) return app('json')->fail('商户分类不存在'); if ($adminRepository->fieldExists('account', $data['mer_account'])) return app('json')->fail('账号已存在'); $this->repository->createMerchant($data); return app('json')->success('添加成功'); } /** * @param int $id * @return mixed * @throws FormBuilderException * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020-04-16 */ public function updateForm($id) { if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); return app('json')->success(formToData($this->repository->updateForm($id))); } /** * @param int $id * @param MerchantValidate $validate * @param MerchantCategoryRepository $merchantCategoryRepository * @return mixed * @throws DbException * @author xaboy * @day 2020-05-06 */ public function update($id, MerchantValidate $validate, MerchantCategoryRepository $merchantCategoryRepository) { $data = $this->checkParam($validate, true); if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); if ($this->repository->fieldExists('mer_name', $data['mer_name'], $id)) return app('json')->fail('商户名已存在'); if ($data['mer_phone'] && isPhone($data['mer_phone'])) return app('json')->fail('请输入正确的手机号'); if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id'])) return app('json')->fail('商户分类不存在'); unset($data['mer_account'], $data['mer_password']); unset($data['mer_type']); $this->repository->update($id, $data); return app('json')->success('编辑成功'); } /** * @param int $id * @return mixed * @throws DbException * @author xaboy * @day 2020-04-17 */ public function delete($id) { if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $this->repository->update($id, ['is_del' => 1]); //下架商品 $this->repository->MerUpdate(['mer_id'=>$id],['status'=>-2]); return app('json')->success('编辑成功'); } /** * @param MerchantValidate $validate * @param bool $isUpdate * @return array * @author xaboy * @day 2020-04-17 */ public function checkParam(MerchantValidate $validate, $isUpdate = false) { $data = $this->request->params([['category_id', 0], 'mer_type','mer_name', 'commission_rate', 'real_name', 'mer_phone', 'mer_keyword', 'mer_address', 'mark', ['sort', 0], ['status', 0], ['is_audit', 0], ['is_best', 0], ['is_bro_goods', 0], ['is_bro_room', 0],['is_show_alibaba',0]]); if (!$isUpdate) $data += $this->request->params(['mer_account', 'mer_password']); else $validate->isUpdate(); $validate->check($data); return $data; } /** * @param int $id * @return mixed * @throws DbException * @author xaboy * @day 2020-03-31 */ public function switchStatus($id) { $is_best = $this->request->param('status', 0) == 1 ? 1 : 0; if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $this->repository->update($id, compact('is_best')); Queue::push(ChangeMerchantStatusJob::class, $id); return app('json')->success('修改成功'); } /** * @param $id * @param MerchantAdminRepository $adminRepository * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020/7/7 */ public function login($id, MerchantAdminRepository $adminRepository) { if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); $adminInfo = $adminRepository->merIdByAdmin($id); $tokenInfo = $adminRepository->createToken($adminInfo); $admin = $adminInfo->toArray(); unset($admin['pwd']); $data = [ 'token' => $tokenInfo['token'], 'exp' => $tokenInfo['out'], 'admin' => $admin, 'url' => '/' . config('admin.merchant_prefix') ]; return app('json')->success($data); } /** * TODO 修改复制次数表单 * @param $id * @return mixed * @author Qinii * @day 2020-08-06 */ public function changeCopyNumForm($id) { return app('json')->success(formToData($this->repository->copyForm($id))); } /** * TODO 修改复制次数 * @param $id * @return mixed * @author Qinii * @day 2020-08-06 */ public function changeCopyNum($id) { $data = $this->request->params(['type','num']); $num = $data['num']; if($data['type'] == 2){ $mer_num = $this->repository->getCopyNum($id); if(($mer_num - $num)<0) return app('json')->fail('剩余次数不足'); $num = '-'.$data['num']; } $arr = [ 'type' => 'sys', 'num' => $num, 'message' => '平台修改「'.$this->request->adminId().'」', ]; app()->make(ProductCopyRepository::class)->add($arr,$id); return app('json')->success('修改成功'); } /** * @param $id * @return mixed * @throws FormBuilderException * @author xaboy * @day 2020-05-07 */ public function changeProForm($id) { if (!$this->repository->exists($id)) return app('json')->fail('数据不存在'); return app('json')->success(formToData($this->repository->changeProForm($id))); } /* * 更改用户推荐信息 * cabbage * 2020-11-04 * */ public function changePro($id,MerchantRepository $repository) { $spread_account = $this->request->param('spread_account'); if (!$spread_account || !$id){ return app('json')->fail('参数丢失'); } if($repository->update_spread($id,$spread_account)){ return app('json')->success("修改成功"); }else{ return app('json')->fail("失败"); } } public function mechant_expire() { $data=Db::name('merchant')->where('status',1)->where('expire_time','<',time())->select(); $num=0; $id=''; if(!$data->isEmpty()){ foreach ($data as $k=>$v){ $num++; $id.=$v['mer_id'].','; Db::name('merchant')->where('mer_id',$v['mer_id'])->update(['status'=>0]); } } $id=rtrim($id,','); return app('json')->success('商户到期一共'.$num.'个'.'商户ID分别是'.$id); } public function update_dc(){ $data = $this->request->params(['mer_id','dc_id']); if(in_array('',$data)){ return app('json')->fail('参数丢失'); } $res = Db::name('merchant') -> where('mer_id',$data['mer_id']) -> update(['dc_id'=>$data['dc_id'],'merchant_type'=>3]); if ($res){ return app('json')->success('修改成功'); } } public function update_level(){ $data = $this->request->params(['mer_id','level']); if(in_array('',$data)){ return app('json')->fail('参数丢失'); } $res = Db::name('merchant') -> where('mer_id',$data['mer_id']) -> update(['merchant_level'=>$data['level']]); if ($res){ return app('json')->success('修改成功'); } } }