where('status', '=', $params['status']); } if ($params['store_name']) { $model = $model->where('store_name', 'like', '%' . trim($params['store_name']) . '%'); } if(isset($params['area_ids'])&&$params['area_ids']){ $model = $model->where('area_id', 'in', $params['area_ids']); } // 查询列表数据 $list = $model->with(['user', 'category','area', 'businessImage']) ->order(['create_time' => 'desc']) ->paginate($params); // 整理列表数据并返回 return $this->setListData($list, true); } /** * 设置商品展示的数据 */ protected function setListData($data, $isMultiple = true, callable $callback = null) { if (!$isMultiple) $dataSource = [&$data]; else $dataSource = &$data; return $data; } /** * 详情 */ public static function detail($branch_apply_id, $with = []) { return (new static())->with($with)->find($branch_apply_id); } /** * 审核 */ public function audit($data) { // 开启事务 $this->startTrans(); try { if ($data['status'] == 2) { if (empty($data['content'])) { $this->error = "备注不能为空"; return false; } $template_code = "branch_reject_code"; UserModel::updateType($this['user_id'], 1); // 申请状态 $this->save(['status' => 2]); } else if ($data['status'] == 1) { $template_code = "branch_pass_code"; //用户为供应商 UserModel::updateType($this['user_id'], 2); // 申请状态 $this->save(['status' => 1]); //添加供应商账号更新 $branch_data = [ 'user_name' => $this['mobile'], 'password' => $this['password'], 'name' => $this['store_name'], 'user_id' => $this['user_id'], 'real_name' => $this['user_name'], 'link_phone' => $this['mobile'], 'link_name' => $this['user_name'], 'business_id' => $this['business_id'], 'category_id' => $this['category_id'], 'area_id' => $this['area_id'], 'app_id' => self::$app_id ]; // 供应商状态,如果类目保证金为0,则直接通过,否则需要交纳保证金 $category = BranchCategoryModel::detail($this['category_id']); if($category['deposit_money'] > 0){ $branch_data['status'] = 20; } else{ $branch_data['status'] = 0; } $BranchModel = new BranchModel; if (!$BranchModel->addData($branch_data)) { $this->error = $BranchModel->getError(); return false; } } $smsConfig = SettingModel::getItem('sms', self::$app_id); $send_template_code = $smsConfig['engine']['aliyun'][$template_code]; $SmsDriver = new SmsDriver($smsConfig); $SmsDriver->sendSms($this['mobile'], $send_template_code, ''); $this->commit(); return true; } catch (\Exception $e) { $this->error = $e->getMessage(); $this->rollback(); return false; } } /** * 获取供应商申请数 */ public static function getApplyCount(){ return (new static())->where('status', '=', 0)->count(); } /** * 获取供应商申请数 */ public static function getApplyCountByDay($day){ $startTime = strtotime($day); return (new static())->where('create_time', '>=', $startTime) ->where('create_time', '<', $startTime + 86400) ->count(); } /** * 获取供应商申请统计数量 */ public function getApplyData($startDate = null, $endDate = null, $type) { $model = $this; if(!is_null($startDate)){ $model = $model->where('create_time', '>=', strtotime($startDate)); } if(is_null($endDate)){ $model = $model->where('create_time', '<', strtotime($startDate) + 86400); }else{ $model = $model->where('create_time', '<', strtotime($endDate) + 86400); } return $model->count(); } }