| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace app\traits\account; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use app\model\BusinessFlow; | 
					
						
							| 
									
										
										
										
											2021-12-20 10:52:03 +08:00
										 |  |  | use think\Collection; | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | trait BusinessFlowTrait | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取关注的商家列表 | 
					
						
							|  |  |  |      * @param $accountCode | 
					
						
							|  |  |  |      * @param $page | 
					
						
							|  |  |  |      * @param $size | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |      * @param $keyword | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |      * @return | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |     public function getBusinessFlowList($accountCode, $page, $size,$keyword=null) | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-12-20 10:52:03 +08:00
										 |  |  |         $data = [ | 
					
						
							|  |  |  |             'total' => 0, | 
					
						
							|  |  |  |             'current' => $page, | 
					
						
							|  |  |  |             'size' => $size, | 
					
						
							|  |  |  |             'list' => new Collection(), | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $model = BusinessFlow::alias("a") | 
					
						
							|  |  |  |             ->join("business b", "a.business_code = b.code") | 
					
						
							|  |  |  |             ->where("a.user_code", $accountCode) | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |             ->when(!empty($keyword), function ($q) use ($keyword) { | 
					
						
							|  |  |  |                 $q->where("b.business_name", "like", "%{$keyword}%"); | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |             ->field([ | 
					
						
							|  |  |  |                 "b.id", | 
					
						
							|  |  |  |                 "b.code as businessCode", | 
					
						
							|  |  |  |                 "b.business_name as businessName", | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |                 "b.background", | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |                 "a.create_time as createTime", | 
					
						
							|  |  |  |                 "a.user_code as userCode", | 
					
						
							| 
									
										
										
										
											2021-12-20 10:52:03 +08:00
										 |  |  |             ]); | 
					
						
							|  |  |  |         $data["total"] = $model->count(); | 
					
						
							|  |  |  |         $data["list"] = $model | 
					
						
							|  |  |  |             ->page($page, $size) | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |             ->order("a.id desc") | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |             ->select(); | 
					
						
							| 
									
										
										
										
											2021-12-20 10:52:03 +08:00
										 |  |  |         return $data; | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-06 18:56:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取关注的商家的code | 
					
						
							|  |  |  |      * @param $accountCode | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getBusinessFlowCodeArray($accountCode) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return BusinessFlow::where("user_code",$accountCode) | 
					
						
							|  |  |  |             ->column("business_code"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 获取关注的商家的code | 
					
						
							|  |  |  |      * @param $accountCode | 
					
						
							|  |  |  |      * @param $businessCode | 
					
						
							|  |  |  |      * @return BusinessFlow|array|\think\Model|null | 
					
						
							|  |  |  |      * @throws \think\db\exception\DataNotFoundException | 
					
						
							|  |  |  |      * @throws \think\db\exception\DbException | 
					
						
							|  |  |  |      * @throws \think\db\exception\ModelNotFoundException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function hasBusinessFlow($accountCode,$businessCode) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return BusinessFlow::where("user_code",$accountCode) | 
					
						
							|  |  |  |             ->where("business_code",$businessCode) | 
					
						
							|  |  |  |             ->find(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 关注一个商家 | 
					
						
							|  |  |  |      * @param $accountCode | 
					
						
							|  |  |  |      * @param $businessCode | 
					
						
							|  |  |  |      * @param $businessName | 
					
						
							|  |  |  |      * @return BusinessFlow|\think\Model | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function createBusinessFlow($accountCode,$businessCode,$businessName) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return BusinessFlow::create([ | 
					
						
							|  |  |  |             "user_code"=>$accountCode, | 
					
						
							|  |  |  |             "business_code"=>$businessCode, | 
					
						
							|  |  |  |             "business_name"=>$businessName, | 
					
						
							|  |  |  |             "create_time"=>date("Y-m-d H:i:s") | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |