| 
									
										
										
										
											2022-05-25 19:35:57 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | namespace app\model; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use think\Collection; | 
					
						
							|  |  |  | use think\db\exception\DataNotFoundException; | 
					
						
							|  |  |  | use think\db\exception\DbException; | 
					
						
							|  |  |  | use think\db\exception\ModelNotFoundException; | 
					
						
							|  |  |  | use think\model\relation\HasOne; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * 活动商品订单 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Class OrderActivity | 
					
						
							|  |  |  |  * @package app\model | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class OrderActivity extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 设为已付款 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string  $orderCoding | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function setPaid(string $orderCoding): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::where('coding', $orderCoding)->save([ | 
					
						
							|  |  |  |             'is_paid' => self::COMMON_ON, | 
					
						
							|  |  |  |             'paid_at' => date('Y-m-d H:i:s') | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 订单相关信息取消(软删除) | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string  $orderCoding | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function cancel(string $orderCoding): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::where('coding', $orderCoding)->save([ | 
					
						
							| 
									
										
										
										
											2022-06-02 15:38:51 +08:00
										 |  |  |             'status'  => Order::STATUS_CANCEL, | 
					
						
							| 
									
										
										
										
											2022-05-25 19:35:57 +08:00
										 |  |  |             'deleted_at' => date('Y-m-d H:i:s') | 
					
						
							|  |  |  |         ]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 历史记录 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  array  $where | 
					
						
							|  |  |  |      * @param  array  $field | 
					
						
							|  |  |  |      * @return OrderActivity[]|array|Collection | 
					
						
							|  |  |  |      * @throws DataNotFoundException | 
					
						
							|  |  |  |      * @throws DbException | 
					
						
							|  |  |  |      * @throws ModelNotFoundException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function history(array $where, array $field = []) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return self::where($where)->field($field)->select(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 订单信息 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return HasOne | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function orderInfo(): HasOne | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasOne(Order::class, 'coding', 'coding'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 用户信息 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return HasOne | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function account(): HasOne | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasOne(Account::class, 'id', 'account_id')->withField(['id', 'nickname', 'real_name']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |