| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace app\controller\manager; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use app\model\Account; | 
					
						
							|  |  |  | use app\model\Coupon; | 
					
						
							|  |  |  | use app\repository\AccountRepository; | 
					
						
							|  |  |  | use Exception; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use think\response\Json; | 
					
						
							|  |  |  | use think\response\View; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * 消费者 | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | class Consumer extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 列表 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return Json|View | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($this->request->isPost()) { | 
					
						
							|  |  |  |             $repo = AccountRepository::getInstance(); | 
					
						
							|  |  |  |             $keyword = $this->request->param('keyword/s', ''); | 
					
						
							|  |  |  |             $page = $this->request->param('page/d', 1); | 
					
						
							|  |  |  |             $size = $this->request->param('size/d', 30); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 16:30:22 +08:00
										 |  |  |             $whereMap = [ | 
					
						
							|  |  |  |                 ["type", "<>", Account::type_business] | 
					
						
							|  |  |  |             ]; | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |             $orders = ['id' => 'desc']; | 
					
						
							|  |  |  |             if (!empty($keyword)) { | 
					
						
							|  |  |  |                 $whereMap[] = ['nick_name', 'like', "%$keyword%"]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $list = $repo->findList($whereMap, [], $page, $size, function ($q) { | 
					
						
							|  |  |  |                 return $q->with("tag"); | 
					
						
							|  |  |  |             }, $orders); | 
					
						
							|  |  |  |             $list["list"]->each(function ($item) { | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |                 //优惠券领取总数
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |                 $item->coupon_total_count = Coupon::where(["consumer_code" => $item->user_code])->count("id"); | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |                 //优惠券使用总数
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |                 $item->coupon_used_count = Coupon::where(["consumer_code" => $item->user_code])->where("is_verificated", Coupon::is_verificated_on)->count("id"); | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |                 //优惠券未使用总数
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |                 $item->coupon_not_use_count = Coupon::where(["consumer_code" => $item->user_code])->where("is_verificated", Coupon::is_verificated_off)->count("id"); | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 //优惠红包总金额
 | 
					
						
							|  |  |  |                 $item->consumer_coupon_bill_total = AccountRepository::getInstance()->consumerCouponBillTotal($item->user_code); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $this->json(0, 'success', $list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $this->view(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 消费者详情 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return Json|View | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function info() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $id = input("id/d", 0); | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |         $sign = input("sign/d", 0); | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |         $consumer = Account::findOne(["id" => $id], [], function ($q) { | 
					
						
							|  |  |  |             return $q->with("tag"); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |         //只查询优惠券持有
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |         if ($this->request->isPost()) { | 
					
						
							|  |  |  |             $repo = AccountRepository::getInstance(); | 
					
						
							|  |  |  |             $page = $this->request->param('page/d', 1); | 
					
						
							|  |  |  |             $size = $this->request->param('size/d', 30); | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |             $where = [["consumer_code", "=", $consumer['user_code']]]; | 
					
						
							|  |  |  |             if ($sign) { | 
					
						
							|  |  |  |                 $where[] = ["is_verificated", "=", Coupon::is_verificated_on]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $list = $repo->consumerCouponList($where, $page, $size); | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |             $time = time(); | 
					
						
							|  |  |  |             $list["list"]->each(function ($item) use ($time) { | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |                 if (strtotime($item['end_time']) < $time) { | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |                     $item->time_state = '已过期'; | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |                     $item->time_state = '未过期'; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |             return $this->json(0, 'success', $list); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |         if (empty($consumer)) { | 
					
						
							|  |  |  |             return $this->json(4001, "消费者不存在"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $rep = AccountRepository::getInstance(); | 
					
						
							|  |  |  |         //评论总数数
 | 
					
						
							|  |  |  |         $this->data["totalComment"] = $rep->consumerTotalComment($consumer["user_code"]); | 
					
						
							|  |  |  |         //评论总数数
 | 
					
						
							|  |  |  |         $this->data["totalTheMonthComment"] = $rep->consumerTheMonthTotalComment($consumer["user_code"]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |         //优惠券领取总数
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |         $this->data["couponTotalCount"] = $rep->consumerTotalCoupon($consumer["user_code"]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |         //优惠券使用总数
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |         $this->data["couponUsedTotalCount"] = $rep->consumerUsedTotalCoupon($consumer["user_code"]); | 
					
						
							| 
									
										
										
										
											2022-01-20 13:56:21 +08:00
										 |  |  |         //优惠券未使用总数
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |         $this->data["couponNotUsedTotalCount"] = $rep->consumerNotUsedTotalCoupon($consumer["user_code"]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->data["consumer"] = $consumer->toArray(); | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |         $this->data["sign"] = $sign; | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this->view(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 18:14:21 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * 黑名单列表 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return Json|View | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function blankList() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-30 18:31:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 18:14:21 +08:00
										 |  |  |         if ($this->request->isPost()) { | 
					
						
							|  |  |  |             $repo = AccountRepository::getInstance(); | 
					
						
							|  |  |  |             $keyword = $this->request->param('keyword/s', ''); | 
					
						
							| 
									
										
										
										
											2021-11-30 18:31:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 18:14:21 +08:00
										 |  |  |             $page = $this->request->param('page/d', 1); | 
					
						
							|  |  |  |             $size = $this->request->param('size/d', 30); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $whereMap = [ | 
					
						
							| 
									
										
										
										
											2021-12-23 16:30:22 +08:00
										 |  |  |                 //["type", "=", Account::type_consumer],
 | 
					
						
							| 
									
										
										
										
											2021-11-22 18:14:21 +08:00
										 |  |  |                 ["blank_total", ">", 0], | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |             $orders = ['id' => 'desc']; | 
					
						
							|  |  |  |             if (!empty($keyword)) { | 
					
						
							|  |  |  |                 $whereMap[] = ['nick_name', 'like', "%$keyword%"]; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-11-30 18:31:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |             $list = $repo->findList($whereMap, [], $page, $size, null, $orders); | 
					
						
							|  |  |  |             $time = time(); | 
					
						
							|  |  |  |             $list["list"]->each(function ($item) use ($time) { | 
					
						
							| 
									
										
										
										
											2021-11-22 18:14:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |                 //禁言总时长
 | 
					
						
							|  |  |  |                 $item->blank_total_format = formatBlankTime(date("Y-m-d H:i:s",$time + ($item->blank_total * 60)),    date("Y-m-d H:i:s",$time ),); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //                echo  date("Y-m-d H:i:s",$time + $item->blank_total * 60);
 | 
					
						
							|  |  |  | //                echo  date("Y-m-d H:i:s",$time + $item->blank_total * 60);
 | 
					
						
							|  |  |  | //                echo  $item->blank_time;
 | 
					
						
							|  |  |  |                 //剩余禁言总时长
 | 
					
						
							|  |  |  |                 if(!empty($item->blank_time) && strtotime($item->blank_time)>$time){ | 
					
						
							|  |  |  |                     $item->surplus_blank_total_format = formatBlankTime( | 
					
						
							|  |  |  |                         date("Y-m-d H:i:s",$time ), | 
					
						
							|  |  |  |                         $item->blank_time); | 
					
						
							|  |  |  |                 }else{ | 
					
						
							|  |  |  |                     $item->surplus_blank_total_format = ''; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2021-11-22 18:14:21 +08:00
										 |  |  |             return $this->json(0, 'success', $list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $this->view(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  | } |