'ID', 'mall_id' => 'Mall ID', 'coupon_id' => 'Coupon ID', 'store_id' => 'Store ID', 'member_level' => 'Member Level', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * 保存数据 * @param $mall_id * @param $coupon_id * @param $member_level * @return bool * @throws \yii\db\Exception */ public static function setData($mall_id,$coupon_id,$store_id,$member_level){ try{ if($mall_id && $coupon_id&&$member_level){ $count = self::deleteAll([ 'and', ['mall_id' => $mall_id], ['store_id' => $store_id], ['coupon_id' => $coupon_id], ['not in','member_level',$member_level] ]); $exist_level_ids = self::find()->select('member_level') ->where(['member_level'=>$member_level,'mall_id'=>$mall_id,'store_id'=>$store_id,'coupon_id' => $coupon_id])->column(); $insert = []; $now = time(); foreach($member_level as $key => $level){ if(in_array($level,$exist_level_ids)) continue; $insert[] = [$mall_id,$coupon_id,$store_id,$level,$now,$now]; } $field = ['mall_id', 'coupon_id','store_id','member_level','created_at','updated_at']; // 批量插入数据 Yii::$app->db->createCommand()->batchInsert(self::tableName(), $field, $insert)->execute(); } return true; }catch(Exception $e){ self::$static_error = $e->getMessage(); return false; } } }