123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\youzan\logic;
- use app\youzan\model\GoodPlatform;
- use think\Exception;
- use think\facade\Cache;
- use think\facade\Db;
- //商品处理层
- class Goodup
- {
- //redis队列对应的key,要与有赞对接项目中的key保持一致,不要轻易修改
- private static $redis_good_up_online_key = 'yz_good_up_online';
- private static $redis_good_offline_key = 'yz_good_offline';
- //添加商品上线到处理队列中
- public static function youzanGoodUpOnline(int $good_platform_id = 0, array $data = [])
- {
- Db::startTrans();
- try {
- $db = new GoodPlatform();
- $rs = $db
- ->fetchSql()
- ->field('gp.id,gp.spuCode,gp.skuCode,gp.exam_status,gp.status,gb.good_name,gb.weight,gb.good_img')
- ->alias('gp')
- ->where(['gp.id' => $good_platform_id, 'gp.is_del' => $db::$del_normal])
- ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
- ->findOrEmpty();
- halt($rs);
- if ($rs->isEmpty()) throw new Exception('该商品上线记录不存在');
- if ($rs->exam_status != $db::$exam_status_6) throw new Exception('该商品尚未上线成功');
- if ($rs->status == $db::$status_online_success) throw new Exception('该商品已经在有赞平台上线了');
- $userinfo = GetUserInfo($data['token']);
- //入队列
- Cache::store("redis")->handler()->lPush(self::$redis_good_up_online_key, json_encode([
- 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
- 'item_type' => 0,//0实物商品
- 'title' => $rs->good_name,//商品标题
- 'is_support_barter' => $data['support_refund'],//是否支持换货。1:支持;0:不支持
- 'desc' => '我是商品描述',//商品描述
- 'item_weight' => $rs->weight,
- 'category_id' => $data['cat_id'],
- 'auto_listing_time' => '0',//0立即售出,传值表示定时(要大于当前时间戳)
- 'stock_deduct_mode' => 0,//0拍下减库存
- 'is_display' => 1,//1上架商品
- 'quantity' => '1111111111',//库存数,先随便写个数,待 @戴 确定
- 'hide_stock' => 0,//0显示库存,1不显示库存
- 'origin' => $data['origin'],//系统售价
- 'price' => $data['price'],//最后售价
- 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
- 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
- 'good_platform_id' => $good_platform_id,
- 'good_img' => $rs->good_img,//图片集合
- 'post_fee' => 0,//运费,单位分,整数
- 'sell_point' => '',//商品卖点信息
- 'yz_cat_id' => $data['yz_cat_id'],//有赞类目id
- ]));
- //更新状态值
- $db->where('id', $good_platform_id)
- ->where('status', '<>', $db::$status_online_success)
- ->save([
- 'status' => $db::$status_online_ing,
- 'updatetime' => date('Y-m-d H:i:s'),
- ]);
- Db::commit();
- return app_show(0, '操作成功');
- } catch (Exception $exception) {
- Db::rollback();
- return error_show(1005, $exception->getMessage());
- }
- }
- //添加商品下线到处理队列中
- public static function youzanGoodOffline(int $good_platform_id = 0, array $data = [])
- {
- Db::startTrans();
- try {
- $db = new GoodPlatform();
- $rs = $db
- ->field('gp.id,gp.skuCode,gp.exam_status,gp.status')
- ->alias('gp')
- ->where(['gp.id' => $good_platform_id, 'gp.is_del' => $db::$del_normal])
- ->findOrEmpty();
- if ($rs->isEmpty()) throw new Exception('该商品上线记录不存在');
- if ($rs->exam_status != $db::$exam_status_8) throw new Exception('该商品尚未下线成功');
- if ($rs->status == $db::$status_offline) throw new Exception('该商品已经在有赞平台下线了');
- $userinfo = GetUserInfo($data['token']);
- //入队列
- Cache::store("redis")->handler()->lPush(self::$redis_good_offline_key, json_encode([
- 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
- 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
- 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
- 'good_platform_id' => $good_platform_id,
- ]));
- Db::commit();
- return app_show(0, '操作成功');
- } catch (Exception $exception) {
- Db::rollback();
- return error_show(1005, $exception->getMessage());
- }
- }
- }
|