|
@@ -137,21 +137,40 @@ class Live extends Controller
|
|
|
*/
|
|
|
protected function _form_result($result)
|
|
|
{
|
|
|
- $live_info = Db::table('store_live')->find($result);
|
|
|
+ /*$live_info = Db::table('store_live')->find($result);
|
|
|
$live_goods = json_decode($live_info['detail'],true);
|
|
|
- Db::table('store_live_goods')->where(['live_id'=>$result])->delete();
|
|
|
+ //Db::table('store_live_goods')->where(['live_id'=>$result])->delete();
|
|
|
+ $ch_goods = Db::table('store_live_goods')->where(['live_id'=>$result])->select();
|
|
|
+ $ck_ids = array_column($ch_goods,'goods_id');
|
|
|
+ $new_ids = array_column($live_goods,'goods_id');
|
|
|
$int_data = [];
|
|
|
foreach ($live_goods as $v) {
|
|
|
- $int_data[]=[
|
|
|
- 'live_id' => $result ,
|
|
|
- 'goods_id' => $v['goods_id'] ,
|
|
|
- 'st_at' => $v['gl_st'] ,
|
|
|
- 'end_at' => $v['gl_end'] ,
|
|
|
- 'live_status' => $live_info['status'] ,
|
|
|
- 'create_at' => date('Y-m-d H:i:s') ,
|
|
|
- ];
|
|
|
+ // 需要新加
|
|
|
+ if(!in_array($v['goods_id'],$ck_ids)) {
|
|
|
+ $int_data[]=[
|
|
|
+ 'live_id' => $result ,
|
|
|
+ 'goods_id' => $v['goods_id'] ,
|
|
|
+ 'st_at' => $v['gl_st'] ,
|
|
|
+ 'end_at' => $v['gl_end'] ,
|
|
|
+ 'live_status' => $live_info['status'] ,
|
|
|
+ 'create_at' => date('Y-m-d H:i:s') ,
|
|
|
+ ];
|
|
|
+ }else if(in_array($v['goods_id'],$ck_ids)) {// 更新
|
|
|
+ $up_data = [
|
|
|
+ 'st_at' => $v['gl_st'] ,
|
|
|
+ 'end_at' => $v['gl_end'] ,
|
|
|
+ 'live_status' => $live_info['status'] ,
|
|
|
+ 'create_at' => date('Y-m-d H:i:s') ,
|
|
|
+ ];
|
|
|
+ Db::table('store_live_goods')->where(['live_id'=>$result,'goods_id'=>$v['goods_id']])->update($up_data);
|
|
|
+ }
|
|
|
}
|
|
|
- Db::table('store_live_goods')->insertAll($int_data);
|
|
|
+ if(!empty($int_data)) Db::table('store_live_goods')->insertAll($int_data);
|
|
|
+ // 删掉多余的
|
|
|
+ foreach ($ck_ids as $cv) {
|
|
|
+ if(!in_array($cv,$new_ids)) Db::table('store_live_goods')->where(['live_id'=>$result,'goods_id'=>$cv])->delete();
|
|
|
+ }*/
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|