where('name', 'like', '%'.$postdata["keyword"].'%'); } return $model->where('is_delete', '=', 0) ->where('project_type', '=', 1) ->where('user_id', '=', $user_id) ->order(['create_time' => 'desc']) ->paginate($postdata); } /** * 新增记录 */ public function add($postdata,$supply,$pay_price) { $data = json_decode($postdata["formData"],true); if (empty($data['name'])) { $this->error = '请输入标题'; return false; } if (empty($data['category_id'])) { $this->error = '请选择分类'; return false; } if (empty($data['price'])) { $this->error = '请输入您的价格'; return false; } if (empty($data['content'])) { $this->error = '请输入您的详细描述'; return false; } $save_data =[ 'user_id'=>$supply["user_id"], 'name'=>$data["name"], 'category_id'=>$data["category_id"], 'price'=>$data["price"], 'content'=>$data["content"], 'product_content'=>$data["product_content"], 'product_case'=>$data["product_case"], 'detail'=>$data["detail"], 'project_type'=>1, 'is_show'=>$data["is_show"], 'app_id'=>self::$app_id, ]; if(!empty($data["finish_time"]) && $data["finish_time"] != '请选择日期'){ $save_data["finish_time"] = strtotime($data["finish_time"]); }else{ $save_data["finish_time"] = ''; } return $this->transaction(function () use ($data, $save_data,$pay_price) { // 记录内容 $this->save($save_data); // 记录图片 $this->saveAllImages($this['project_id'],$data); // 记录标签 $this->saveTag($this['project_id'],$data); //减少连盟币 if($pay_price>0){ (new UserModel())->where('user_id', '=', $save_data['user_id'])->dec('points',$pay_price)->update(); PointsLogModel::add([ 'user_id' => $save_data['user_id'], 'value' => -$pay_price, 'describe' => "发布供应消耗连盟币", 'app_id' => $save_data['app_id'], ]); } return $this['project_id']; }); } /** * 更新记录 */ public function edit($postdata) { $data = json_decode($postdata["formData"],true); if (empty($data['name'])) { $this->error = '请输入标题'; return false; } if (empty($data['category_id'])) { $this->error = '请选择分类'; return false; } if (empty($data['price'])) { $this->error = '请输入您的价格'; return false; } if (empty($data['content'])) { $this->error = '请输入您的详细描述'; return false; } $save_data =[ 'name'=>$data["name"], 'category_id'=>$data["category_id"], 'price'=>$data["price"], 'content'=>$data["content"], 'product_content'=>$data["product_content"], 'product_case'=>$data["product_case"], 'detail'=>$data["detail"], 'is_show'=>$data["is_show"], 'status'=>0, ]; if(!empty($data["finish_time"]) && $data["finish_time"] != '请选择日期'){ $save_data["finish_time"] = strtotime($data["finish_time"]); }else{ $save_data["finish_time"] = ''; } return $this->transaction(function () use ($data, $save_data) { // 记录内容 $this->where("project_id","=",$data["project_id"])->save($save_data); // 记录图片 $this->saveAllImages($data['project_id'],$data); // 记录标签 $this->saveTag($data['project_id'],$data); return true; }); } /** * 记录图片 */ private function saveAllImages($id,$formData) { (new ReleaseProjectImageModel())->where("project_id","=",$id)->delete(); // 生成图片数据 if(!empty($formData['image_list'])){ $imageData = []; foreach ($formData['image_list'] as $imageId) { $imageData[] = [ 'project_id' => $id, 'image_id' => !empty($imageId['image_id']) ? $imageId['image_id'] : $imageId['file_id'], 'app_id' => self::$app_id ]; } $model = new ReleaseProjectImageModel; return !empty($imageData) && $model->saveAll($imageData); } return true; } /** * 记录标签 */ private function saveTag($id,$formData) { (new ReleaseProjectTagModel())->where("project_id","=",$id)->delete(); // 生成数据 if(!empty($formData['tag_list'])){ $tagData = []; foreach ($formData['tag_list'] as $val) { $tagData[] = [ 'project_id' => $id, 'tag_id' => $val, 'app_id' => self::$app_id ]; } $model = new ReleaseProjectTagModel; return !empty($tagData) && $model->saveAll($tagData); } return true; } /** * 软删除 */ public function setDelete($id) { return $this->where("project_id","=",$id)->save(['is_delete' => 1]); } }