| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\jobs;
- use app\constants\OptionSetting;
- use app\models\Goods;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- /**
- * 用于平台修改商品后自动同步所有门店该商品属性
- */
- class SetCloudGoodsStatus extends BaseObject implements JobInterface
- {
- public int $cloud_goods_id;
- public int $store_id;
- public string $attr;
- public array $attr_id_list;
- public string $goods_name;
- public function execute($queue)
- {
- try {
- $goods_url = "/goods/getAttrParams";
- $cloud_goods_id = $this->cloud_goods_id;
- $store_id = $this->store_id;
- $attr = $this->attr;
- $attr_id_list = $this->attr_id_list;
- $goods_name = $this->goods_name;
- $param = [
- 'id' => $cloud_goods_id
- ];
- //请求接口
- $domain = (new OptionSetting)->getCloudDomainName();
- $goodsInfo = cloud_post($domain.$goods_url,$param);
- $goodsInfo = json_decode($goodsInfo, true);
- // debug_log($goodsInfo ,'ptOrderLog.log');
- $goodsInfo = $goodsInfo['data'];
- //如果没有上架或审核未通过则不允许购买
- if ((int)$goodsInfo['status'] === 0 || (int)$goodsInfo['is_audit'] !== 2) {
- //商品下架
- Goods::updateAll(['status' => 0, 'store_id' => $store_id],['cloud_goods_id' => $cloud_goods_id]);
- }
- //如果使用规格
- if (!empty($goodsInfo['use_attr']) && (int)$goodsInfo['use_attr'] === 1) {
- $goods_2 = new Goods();
- $goods_2->attr = $attr;
- $res_attr = $goods_2->getAttrGroupList();
- if ($res_attr) {
- foreach ($res_attr as &$attr_item) {
- unset($attr_item->attr_group_id);
- foreach ($attr_item->attr_list as &$list_item) {
- unset($list_item->attr_id);
- }
- }
- }
- //判断规格名称是否一致
- $res_attr = json_decode(json_encode($res_attr), true);
- if ($res_attr != $goodsInfo['AttrGroupList']) {
- //商品下架
- Goods::updateAll(['status' => 0, 'store_id' => $store_id],['cloud_goods_id' => $cloud_goods_id]);
- }
- $attrs = json_decode($goodsInfo['attrs'], true);
- foreach ($attrs as $attr_item) {
- //如果供货商的商品规格包含购买的
- if (in_array($attr_item['attr_id'], $attr_id_list)) {
- //判断库存无 或者 供货商库存小于购买的商品数量
- if ((int)$attr_item['num'] <= 0) {
- //商品下架
- Goods::updateAll(['status' => 0, 'store_id' => $store_id],['cloud_goods_id' => $cloud_goods_id]);
- }
- }
- }
- } else {
- //如果不使用规格
- if ((int)$goodsInfo['num'] <= 0 || $goodsInfo['name'] != $goods_name) {
- Goods::updateAll(['status' => 0, 'store_id' => $store_id],['cloud_goods_id' => $cloud_goods_id]);
- }
- }
- } catch (\Exception $e) {
- debug_log('云仓规格:' . $e->getMessage() . $e->getLine() . $e->getFile(),'ptOrderLog.log');
- }
- }
- }
|