TimestampBehavior::class, 'value' => time() ] ]; } /** * @inheritdoc */ public function rules() { return [ [['store_id', 'name', 'detail'], 'required'], [['store_id', 'created_at', 'is_enable', 'is_delete', 'updated_at'], 'integer'], [['detail'], 'string'], [['name'], 'string', 'max' => 255], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => 'Store ID', 'name' => '名称', 'detail' => '规则详细', 'created_at' => '创建时间', 'is_enable' => '是否启用:0=否,1=是', 'is_delete' => 'Is Delete', 'updated_at' => '更新时间' ]; } public static function checkLocationGoods($goods_id, $address) { $goods = Goods::findOne($goods_id); $rule_id = $goods->order_rules_buyer_location_id; return self::checkLocation($rule_id, $address); } public static function checkLocationGoodsList($goods_ids, $address, $user_id = 0) { $res = null; foreach ($goods_ids as $gid) { if ($address) { $address_status = self::checkLocationGoods($gid, $address); //检测收货地址是否被限制 $arr = null; if (!$address_status) { $arr = [ 'status' => $address_status, 'msg' => '不支持销售到当前收货地址' ]; } } //检测商品是否有会员限制 //判断会员是否可以购买 $goods = Goods::findOne($gid); // $saas_user = SaasUser::findOne($address->user_id); // $user = User::findOne(['binding' => $saas_user->mobile, 'store_id' => $goods->store_id]); if (!empty($goods->buy_type_info)) { $buy_type_info = json_decode($goods->buy_type_info, true); if ((int)$buy_type_info['type'] === 1) { //会员购买 if (!empty($buy_type_info['member_level'])) { $user = User::findOne($user_id); if (!in_array(0, $buy_type_info['member_level']) && !in_array($user->level, $buy_type_info['member_level'])) { $level = Level::find()->where(['level' => $buy_type_info['member_level'], 'store_id' => $goods->store_id]) ->select('name')->column(); $arr = [ 'status' => false, 'msg' => '仅支持' . implode(',', $level) . '购买', ]; } } } if ((int)$buy_type_info['type'] === 2) { //新用户购买 $order = Order::findOne(['user_id' => $user_id, 'is_pay' => 1]); if (!empty($order)) { $arr = [ 'status' => false, 'msg' => '当前商品仅支持新用户购买', ]; } } } if (!empty($arr)) { $res[$gid] = $arr; } } return $res; } public static function checkLocation($rule_id, $address) { if(!$rule_id) { return true; } $rule = self::findOne(['id' => $rule_id, 'is_delete' => 0]); if(!$rule) { return true; } if (!$rule->is_enable) { return true; } $list = json_decode($rule['detail']); if (empty($list)) { return true; } foreach ($list as $item) { foreach ($item->province_list as $province) { if ($province->id == $address->province_id || $province->id==$address->city_id || $province->id==$address->district_id) { return true; } } } return false; } }