Goodup.php 4.9 KB

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