where(['>', 'id', 0]) ->with(['detail']) ->orderBy('id asc') ->offset(($i - 1) * $page_size)->limit($page_size)->all()) { $order_detail_ids = []; foreach ($order_list as $item){ $temp = array_column($item['detail'],'id'); $order_detail_ids = array_merge($order_detail_ids,$temp); } $store_order_marketing_list = StoreOrderMarketing::lists(['where'=>[['order_detail_id'=>$order_detail_ids]],'index'=>'order_detail_id']); foreach ($order_list as $order){ $score = 0; $score_money = 0; foreach ($order['detail'] as $order_detail){ if(isset($store_order_marketing_list[$order_detail['id']])){ $score+=$store_order_marketing_list[$order_detail['id']]['deduct_score']; $deduct_currency = json_decode($store_order_marketing_list[$order_detail['id']]['deduct_currency'],true); if(!empty($deduct_currency)&&is_array($deduct_currency)){ $score_money+=$deduct_currency['score']['money']; } } } if($score>0 && $score_money>0){ $order->score = $score; $order->score_money = $score_money; $res = $order->save(); var_dump($res); } } $i++; } } /** * {@inheritdoc} */ public function safeDown() { echo "M231016072501UpdateStoreOrder cannot be reverted.\n"; return false; } /* // Use up()/down() to run migration code without a transaction. public function up() { } public function down() { echo "M231016072501UpdateStoreOrder cannot be reverted.\n"; return false; } */ }