zhaojs
2023-10-07 6c7bba2e05c011a3d640b6565a113204228e92e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
 
namespace app\admin\command;
use think\Db;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\api\logic\taoke\device\Dataoke as LogicDataoke;
 
/**
 * 专辑管理
 */
class Album extends Command
{
 
    protected function configure()
    {
        $this->setName('album')->setDescription('同步专辑列表');
    }
 
    /**
     *
     * @param Input $input
     * @param Output $output
     * @return void
     */
    protected function execute(Input $input, Output $output)
    {
        $pageSize = 100;
        $page = 1;
        //获取专辑列表
        $LogicDataoke = new LogicDataoke();
        $albumList = $LogicDataoke->albumList(0,0,$page,$pageSize);
        Db::name('album')->where(['is_delete'=>0])->update(['is_delete'=>1]);
        //Db::name('album_goods')->where(['is_delete'=>0])->update(['is_delete'=>1]);
        if(!empty($albumList)){
            foreach($albumList as $key => $item){
                $album_id = $item['id'];            
                $find = Db::name('album')->where(['album_id'=>$album_id])->find();
                $save_data = [
                    'album_id' => $album_id,
                    'uid' => $item['uid'],
                    'title' => isset($item['title']) ? $item['title'] : '',
                    'label' => isset($item['label']) ? $item['label'] : '',
                    'goods_count' =>  isset($item['goodsCount']) ? $item['goodsCount'] : '',
                    'like_num' =>  isset($item['likeNum']) ? $item['likeNum'] : '',
                    'promote_count' =>  isset($item['promoteCount']) ? $item['promoteCount'] : '',
                    'endType' =>  isset($item['endType']) ? $item['endType'] : '',
                    'release_time' =>  isset($item['releaseTime']) ? $item['releaseTime'] : '',
                    'end_time' =>  isset($item['endTime']) ? $item['endTime'] : '',
                    'good_list_json' =>  isset($item['goodsList']) ? json_encode($item['goodsList']) : '',
                    'update_time' => time(),
                    'is_delete'=>0
                ];
                if(empty($find)){ //新增
                    $save_data['create_time'] = time();
                    Db::name('album')->insert($save_data);
                    $save_anchor = [
                        'uid' => $item['uid'],
                        'nickname' => $item['userName'],
                        'head_img' => $item['headImg'],
                        'user_desc' => $item['userDesc'],
                        'user_good_at' => json_encode($item['userGoodAt']),
                        'view_follow_num' => 0,
                        'user_view' => 0
                    ]; 
                    $find_anchor = Db::name('album_author_info')->where(['uid'=>$item['uid']])->find();
                    if(empty($find_anchor)){
                        Db::name('album_author_info')->insert($save_anchor);
                    }
                }else{
                    $res = Db::name('album')->where(['id'=>$find['id']])->update($save_data); 
                }
                //更新商品列表
                // $goodsList = $LogicDataoke->albumGoodsList($album_id);
                // if(!empty($goodsList)){
                //     $save_goods = [];
                //     foreach($goodsList as $goods){
                //         $save_goods[] = [
                //             'album_id' => $album_id,
                //             'shopType' => isset($goods['shopType']) ? $goods['shopType'] : '',
                //             'activityType' => isset($goods['activityType']) ? $goods['activityType'] : '',
                //             'monthSales' => isset($goods['monthSales']) ? $goods['monthSales'] : '',
                //             'dailySales' => isset($goods['dailySales']) ? $goods['dailySales'] : '',
                //             'couponId' => isset($goods['couponId']) ? $goods['couponId'] : '',
                //             'couponLink' => isset($goods['couponLink']) ? $goods['couponLink'] : '',
                //             'couponPrice' => isset($goods['couponPrice']) ? $goods['couponPrice'] : '',
                //             'goodsId' => isset($goods['goodsId']) ? $goods['goodsId'] : '',
                //             'title' => isset($goods['title']) ? $goods['title'] : '',
                //             'mainPic' => isset($goods['mainPic']) ? $goods['mainPic'] : '',
                //             'specialText' => isset($goods['specialText']) ? $goods['specialText'] : '',
                //             'originPrice' => isset($goods['originPrice']) ? $goods['originPrice'] : '',
                //             'actualPrice' => isset($goods['actualPrice']) ? $goods['actualPrice'] : '',
                //             'create_time' => time(),
                //             'update_time' => time(),
                //             'is_delete' => 0
                //         ];
                //     }
                //     if(!empty($save_goods)){
                //         Db::name('album_goods')->insertAll($save_goods);
                //     }
                // }
            }
            Db::name('album')->where(['is_delete'=>1])->delete();
            //Db::name('album_goods')->where(['is_delete'=>1])->delete();
            
        }
        $output->info("采集成功");
    }
 
}