services = $services; } /** * Common: 申请入驻 * Author: wu-hui * Time: 2024/01/30 14:28 * @return mixed */ public function applyJoin(){ // 参数获取 $data = $this->checkParam(); if((int)$data['supplierApplyId'] > 0){ // 编辑账号信息 app()->make(SystemSupplierApplyServices::class)->editApplyInfo((array)$data); }else{ // 添加账号 app()->make(SystemSupplierApplyServices::class)->createApplyInfo((array)$data); } return app('json')->success('操作成功'); } /** * Common: 申请信息接收 * Author: wu-hui * Time: 2024/01/30 14:18 * @return array */ private function checkParam():array{ // 接收表单参数 $supplierApplyId = (int)$this->request->param('id'); $applyInfo = $this->request->params([ 'invite_agent_id', 'winery_name', 'scale', 'cellar_size', 'corporation_name', 'corporation_phone', ['corporation_id_card',[]], 'chairman_name', 'chairman_phone', ['chairman_id_card',[]], 'contacts_name', 'contacts_phone', 'business_license', 'production_icense', 'circulative_license', ]); $applyInfo['uid'] = $this->request->uid(); // 数据校验 if (empty($applyInfo['invite_agent_id'])) throw new ValidateException('非法请求,无有效邀请人!'); if (empty($applyInfo['winery_name'])) throw new ValidateException('请输入酒厂名称!'); if (empty($applyInfo['scale'])) throw new ValidateException('请输入年产量多少吨!'); if (empty($applyInfo['cellar_size'])) throw new ValidateException('请输入窖池大小!'); if (empty($applyInfo['corporation_name'])) throw new ValidateException('请输入法人姓名!'); if (empty($applyInfo['corporation_phone'])) throw new ValidateException('请输入法人电话!'); if (isPhone($applyInfo['corporation_phone'])) throw new ValidateException('请输入正确的法人电话!'); if (empty($applyInfo['corporation_id_card'])) throw new ValidateException('请上传法人身份证正反面图片!'); if (empty($applyInfo['chairman_name'])) throw new ValidateException('请输入董事长姓名!'); if (empty($applyInfo['chairman_phone'])) throw new ValidateException('请输入董事长电话!'); if (isPhone($applyInfo['chairman_phone'])) throw new ValidateException('请输入正确的董事长电话!'); if (empty($applyInfo['chairman_id_card'])) throw new ValidateException('请上传董事长身份证正反面图片!'); if (empty($applyInfo['contacts_name'])) throw new ValidateException('请输入联系人姓名!'); if (empty($applyInfo['contacts_phone'])) throw new ValidateException('请输入联系人电话!'); if (isPhone($applyInfo['contacts_phone'])) throw new ValidateException('请输入正确的联系人电话!'); if (empty($applyInfo['business_license'])) throw new ValidateException('请上传营业执照!'); if (empty($applyInfo['production_icense'])) throw new ValidateException('请上传生产许可证!'); if (empty($applyInfo['circulative_license'])) throw new ValidateException('请上传流通许可证!'); // 联系人及联系人手机号 $isHas = app()->make(SystemSupplierApplyServices::class) ->searchModel(['contacts_phone'=>$applyInfo['contacts_phone']]) ->when($supplierApplyId > 0,function($query) use ($supplierApplyId){ $query->where('id','<>', $supplierApplyId); }) ->count(); if($isHas >= 1) throw new ValidateException('联系人已经存在,请勿重复申请!'); // 酒厂是否已经存在 $isHas = app()->make(SystemSupplierApplyServices::class) ->searchModel(['winery_name'=>$applyInfo['winery_name']]) ->when($supplierApplyId > 0,function($query) use ($supplierApplyId){ $query->where('id','<>', $supplierApplyId); }) ->count(); if($isHas >= 1) throw new ValidateException('酒厂已经存在,请勿重复申请!'); $nameIsHave = $this->services->isHave('supplier_name',$applyInfo['winery_name']); if($nameIsHave) throw new ValidateException('该酒厂已经入驻,请勿重复申请!'); return compact('supplierApplyId','applyInfo'); } /** * Common: 申请记录 * Author: wu-hui * Time: 2024/01/30 17:11 * @return mixed */ public function applyRecord(){ $search = $this->request->params(['winery_name','contacts_name','contacts_phone','invite_agent_id','status']); $search['uid'] = $this->request->uid(); [$page, $limit] = $this->getPage(); $data = app()->make(SystemSupplierApplyServices::class)->getList($search, $page, $limit); return app('json')->success($data); } /** * Common: 获取单条申请信息 * Author: wu-hui * Time: 2024/01/30 17:35 * @return mixed */ public function applyInfo(){ $applyId = $this->request->param('apply_id'); $data = app()->make(SystemSupplierApplyServices::class)->getSingleInfo(['id'=>$applyId]); return app('json')->success($data); } /** * Common: 获取全部供应商商品 * Author: wu-hui * Time: 2024/02/28 15:50 * @return mixed */ public function goodsList(){ // 参数获取 $search = $this->request->params(['store_name']); [$page, $limit] = $this->getPage(); $data = app()->make(SupplierProductRepository::class)->getList($search, $page, $limit); // 循环处理列表数据 $data['list'] = array_map(function($item){ if(count($item['attrValue']) > 1) $item['attrValue'] = array_column($item['attrValue'],null,'sku'); return $item; },$data['list']); return app('json')->success($data); } /** * Common: 获取当前商户购物车列表 * Author: wu-hui * Time: 2024/03/01 15:06 * @return mixed */ public function cartList(){ // 参数获取 $merId = $this->request->merId(); $list = (array)app()->make(StoreCartRepository::class) ->getSearch([ 'is_pay' => 0, 'is_del' => 0, 'is_new' => 0, 'is_fail' => 0, 'product_type' => 35, 'wine_mer_id' => $merId, ]) ->field(['cart_id','product_type','product_id','product_attr_unique','cart_num','is_batch','batch_num']) ->with([ 'productAttr' => function($query){ $query->field(['product_id','detail','image','price','sku','unique','value_id', 'stock']); }, 'product' => function($query){ $query->field(['product_id','store_name','unit_name','is_batch','batch_num','batch_unit','brand_id']) ->with([ 'brand'=>function($query){ $query->bind(['brand_name']); } ]); } ]) ->select() ->toArray(); return app('json')->success($list); } /** * Common: 获取购物车id列表 * Author: wu-hui * Time: 2024/03/01 15:39 * @return mixed */ public function cartIds(){ // 参数获取 $merId = $this->request->merId(); $ids = (array)app()->make(StoreCartRepository::class) ->getSearch([ 'is_pay' => 0, 'is_del' => 0, 'is_new' => 0, 'is_fail' => 0, 'product_type' => 35, 'wine_mer_id' => $merId, ])->column('cart_id'); return app('json')->success($ids); } /** * Common: 商户购物车 - 新增购买商品&修改购买商品数量 * Author: wu-hui * Time: 2024/03/01 14:24 * @return mixed */ public function cartAdd(){ // 参数获取 $data = $this->request->params([ 'cart_num', 'product_attr_unique', 'product_id', 'is_batch', 'batch_num', ]); $data['product_type'] = 35; $data['source'] = $data['product_type']; $data['source_id'] = $data['product_id']; $merId = $this->request->merId(); // 校验数据 $result = app()->make(ProductRepository::class)->supplyCartCheck($data,$merId); // 添加修改 $cartId = (int)app()->make(StoreCartRepository::class)->getSearch([ 'is_pay' => 0, 'is_del' => 0, 'is_new' => 0, 'is_fail' => 0, 'product_type' => 35, 'product_id' => $data['source_id'], 'wine_mer_id' => $merId, 'product_attr_unique' => $data['product_attr_unique'], ])->value('cart_id'); if($cartId > 0){ // 已经存在 修改数量 app()->make(StoreCartRepository::class)->update($cartId,[ 'cart_num' => $data['cart_num'], 'is_batch' => $data['is_batch'], 'batch_num' => $data['batch_num'] ]); }else{ // 不存在 添加信息 $data['wine_mer_id'] = $merId; $data['mer_id'] = $result['product']['mer_id']; app()->make(StoreCartRepository::class)->create($data); } return app('json')->success(); } /** * Common: 商户购物车 - 删除购买商品 * Author: wu-hui * Time: 2024/03/01 14:49 * @return mixed */ public function cartDel(){ // 参数获取 $data = $this->request->params([ 'product_attr_unique', 'product_id', ]); $data['product_type'] = 35; $data['source'] = $data['product_type']; $data['source_id'] = $data['product_id']; $merId = $this->request->merId(); // 删除操作 $cartId = (int)app()->make(StoreCartRepository::class)->getSearch([ 'is_pay' => 0, 'is_del' => 0, 'is_new' => 0, 'is_fail' => 0, 'product_type' => 35, 'product_id' => $data['source_id'], 'wine_mer_id' => $merId, 'product_attr_unique' => $data['product_attr_unique'], ])->delete(); return app('json')->success(); } }