| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace app\command;
- use app\common\repositories\store\product\ProductRepository;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- class ProductPriceUpdate extends Command
- {
- // 变更数量
- const NUMBER = 5;
- const PRODUCT_IDS = [31053, 32171];
- const MER_ID = 3447;
- protected function configure()
- {
- // 指令配置
- $this->setName('ProductPriceUpdate')
- ->setDescription('商品价格更新');
- }
- protected function execute(Input $input, Output $output)
- {
- $output->writeln('定时任务执行中...');
- $this->priceUpdate();
- $output->writeln('定时任务执行完成');
- }
- private function priceUpdate()
- {
- // 获取商品数据
- $productData = Db::name('store_product')->where(['product_id' => self::PRODUCT_IDS])->select()->toArray();
- /** @var ProductRepository $repository */
- $repository = app()->make(ProductRepository::class);
- foreach ($productData as $product) {
- $log = [
- 'product_id' => $product['product_id'],
- 'old_price' => $product['price'],
- 'number' => self::NUMBER,
- 'new_price' => $product['price'] + self::NUMBER,
- ];
- Db::name('product_price_update_log')->insert($log);
- $attrValue = Db::name('store_product_attr_value')->where(['product_id' => $product['product_id']])->select()->toArray();
- $attrValue[0]['price'] = $attrValue[0]['price'] + self::NUMBER;
- $content = Db::name('store_product_content')->where(['product_id' => $product['product_id']])->field('content')->find();
- $update = [
- 'attr' => [],
- 'attrValue' => $attrValue,
- 'brand_id' => $product['brand_id'],
- 'cate_id' => $product['cate_id'],
- 'commission' => $product['commission'],
- 'content' => $content['content'],
- 'couponData' => [],
- 'extension_type' => $product['extension_type'],
- 'ficti' => $product['ficti'],
- 'give_coupon_ids' => [],
- 'icon_type' => [],
- 'image' => $product['image'],
- 'is_gift_bag' => $product['is_gift_bag'],
- 'is_good' => $product['is_good'],
- 'keyword' => $product['keyword'],
- 'mer_cate_id' => [],
- 'pension' => $product['pension'],
- 'pension_is' => $product['pension_is'],
- 'share_is' => $product['share_is'],
- 'slider_image' => explode(',',$product['slider_image']),
- 'sort' => $product['sort'],
- 'spec_type' => $product['spec_type'],
- 'store_info' => $product['store_info'],
- 'store_name' => $product['store_name'],
- 'temp_id' => $product['temp_id'],
- 'type' => $product['type'],
- 'unit_name' => $product['unit_name'],
- 'volunteer' => $product['volunteer']
- ];
- $repository->update($product['product_id'],$update,self::MER_ID);
- Db::name('product_share')->where('product_id',$product['product_id'])->where('share_channel',1)->update(['url'=>'']);
- }
- // // 获取当前数据
- // $productData = Db::name('store_product')->where(['product_id' => self::PRODUCT_IDS])->field('product_id,price')->select()->toArray();
- // $attrData = Db::name('store_product_attr_value')->where(['product_id' => self::PRODUCT_IDS])->field('product_id,price')->select()->toArray();
- // Db::startTrans();
- // try {
- // foreach ($productData as $product) {
- // $log = [
- // 'product_id' => $product['product_id'],
- // 'old_price' => $product['price'],
- // 'number' => self::NUMBER,
- // 'new_price' => $product['price'] + self::NUMBER,
- // ];
- // Db::name('product_price_update_log')->insert($log);
- //
- // Db::name('store_product')->where(['product_id' => $product['product_id']])->inc('price', self::NUMBER)->update();
- // Db::name('store_product_attr_value')->where(['product_id' => $product['product_id']])->inc('price', self::NUMBER)->update();
- // }
- //
- // ;
- // Db::commit();
- // return true;
- // } catch (\Exception $e) {
- // Db::rollback();
- // throw $e;
- // }
- }
- }
|