isDirty('status')) { switch ($model->status) { case ShopOrderStatusEnum::close: //作废提醒 break; case ShopOrderStatusEnum::wait_shou: //发货提醒 break; } } }); } public static function makeNo() { // 订单流水号前缀 $prefix = self::NO_TAG . date('YmdHis'); for ($i = 0; $i < 10; $i++) { // 随机生成 6 位的数字 $no = $prefix . str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT); // 判断是否已经存在 if (!static::query()->where('order_no', $no)->exists()) { return $no; } } return false; } public function goods() { return $this->hasMany(ShopOrderGood::class, 'order_id')->with(['good'])->select(['nums', 'id', 'good_id', 'jifen', 'total_jifen']); } public function user() { return $this->belongsTo(User::class)->select(['id', 'nickname', 'mobile', 'mobile_encryption', 'mobile_code']); } public function getMSjrMobileAttribute() { if (isset($this->attributes['sjr_mobile_encryption'])) { return Crypt::decryptString($this->attributes['sjr_mobile_encryption']); } return ''; } /** * 根据用户手机号查询用户 * @param $mobile * @return mixed */ public static function byMobileGetIds($mobile) { // return Cache::remember("model:user:byMobileGetIds:{$mobile}", Carbon::now()->addHours(4), function () use ($mobile) { if (strlen($mobile) == 11) { $users = self::query()->where('mobile', mobile_hidden($mobile))->select(['id', 'sjr_mobile', 'sjr_mobile_encryption'])->get(); $len = count($users); if (!$len) return []; $ids = []; foreach ($users as $user) { if ($mobile === $user->m_mobile) { $ids[] = $user->id; } } return $ids; } return self::query()->where('mobile', 'like', "%{$mobile}")->pluck('id'); // }); } }