Goodup.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\youzan\logic;
  3. use app\youzan\model\GoodPlatform;
  4. use think\Exception;
  5. use think\facade\Cache;
  6. use think\facade\Db;
  7. //商品处理层
  8. class Goodup
  9. {
  10. //redis队列对应的key,要与有赞对接项目中的key保持一致,不要轻易修改
  11. private static $redis_good_up_online_key = 'yz_good_up_online';
  12. private static $redis_good_offline_key = 'yz_good_offline';
  13. //添加商品上线到处理队列中
  14. public static function youzanGoodUpOnline(int $good_platform_id = 0, array $data = [])
  15. {
  16. Db::startTrans();
  17. try {
  18. $db = new GoodPlatform();
  19. $rs = $db
  20. ->field('gp.id,gp.spuCode,gp.skuCode,gp.exam_status,gp.status,gb.good_name,gb.weight,gb.good_img')
  21. ->alias('gp')
  22. ->where(['gp.id' => $good_platform_id, 'gp.is_del' => $db::$del_normal])
  23. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode')
  24. ->findOrEmpty();
  25. if ($rs->isEmpty()) throw new Exception('该商品上线记录不存在');
  26. if ($rs->exam_status != $db::$exam_status_6) throw new Exception('该商品尚未上线成功');
  27. if ($rs->status == $db::$status_online_success) throw new Exception('该商品已经在有赞平台上线了');
  28. $userinfo = GetUserInfo($data['token']);
  29. //入队列
  30. Cache::store("redis")->handler()->lPush(self::$redis_good_up_online_key, json_encode([
  31. 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
  32. 'item_type' => 0,//0实物商品
  33. 'title' => $rs->good_name,//商品标题
  34. 'is_support_barter' => $data['support_refund'],//是否支持换货。1:支持;0:不支持
  35. 'desc' => '我是商品描述',//商品描述
  36. 'item_weight' => $rs->weight,
  37. 'category_id' => $data['cat_id'],
  38. 'auto_listing_time' => '0',//0立即售出,传值表示定时(要大于当前时间戳)
  39. 'stock_deduct_mode' => 0,//0拍下减库存
  40. 'is_display' => 1,//1上架商品
  41. 'quantity' => '1111111111',//库存数,先随便写个数,待 @戴 确定
  42. 'hide_stock' => 0,//0显示库存,1不显示库存
  43. 'origin' => $data['origin'],//系统售价
  44. 'price' => $data['price'],//最后售价
  45. 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  46. 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  47. 'good_platform_id' => $good_platform_id,
  48. 'good_img' => $rs->good_img,//图片集合
  49. 'post_fee' => 0,//运费,单位分,整数
  50. 'sell_point' => '',//商品卖点信息
  51. 'yz_cat_id' => $data['yz_cat_id'],//有赞类目id
  52. ]));
  53. //更新状态值
  54. $db->where('id', $good_platform_id)
  55. ->where('status', '<>', $db::$status_online_success)
  56. ->save([
  57. 'status' => $db::$status_online_ing,
  58. 'updatetime' => date('Y-m-d H:i:s'),
  59. ]);
  60. Db::commit();
  61. return app_show(0, '操作成功');
  62. } catch (Exception $exception) {
  63. Db::rollback();
  64. return error_show(1005, $exception->getMessage());
  65. }
  66. }
  67. //添加商品下线到处理队列中
  68. public static function youzanGoodOffline(int $good_platform_id = 0, array $data = [])
  69. {
  70. Db::startTrans();
  71. try {
  72. $db = new GoodPlatform();
  73. $rs = $db
  74. ->field('gp.id,gp.skuCode,gp.exam_status,gp.status')
  75. ->alias('gp')
  76. ->where(['gp.id' => $good_platform_id, 'gp.is_del' => $db::$del_normal])
  77. ->findOrEmpty();
  78. if ($rs->isEmpty()) throw new Exception('该商品上线记录不存在');
  79. if ($rs->exam_status != $db::$exam_status_8) throw new Exception('该商品尚未下线成功');
  80. if ($rs->status == $db::$status_offline) throw new Exception('该商品已经在有赞平台下线了');
  81. $userinfo = GetUserInfo($data['token']);
  82. //入队列
  83. Cache::store("redis")->handler()->lPush(self::$redis_good_offline_key, json_encode([
  84. 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
  85. 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  86. 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  87. 'good_platform_id' => $good_platform_id,
  88. ]));
  89. Db::commit();
  90. return app_show(0, '操作成功');
  91. } catch (Exception $exception) {
  92. Db::rollback();
  93. return error_show(1005, $exception->getMessage());
  94. }
  95. }
  96. }