|
@@ -13,11 +13,6 @@ 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 create(array $data = [])
|
|
|
{
|
|
@@ -131,94 +126,96 @@ class Goodup
|
|
|
public static function youzanGoodUpOnline(int $platform_youzan_id = 0, array $data = [])
|
|
|
{
|
|
|
|
|
|
- Db::startTrans();
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- $db = new PlatformYouzan();
|
|
|
-
|
|
|
- $rs = $db
|
|
|
- ->field('a.id,a.spuCode,a.skuCode,a.exam_status,gb.good_name,gb.weight,gb.good_img,gb.cat_id')
|
|
|
- ->alias('a')
|
|
|
- ->where(['a.id' => $platform_youzan_id, 'a.is_del' => $db::$del_normal])
|
|
|
- ->leftJoin('good_basic gb', 'gb.spuCode=a.spuCode')
|
|
|
- ->findOrEmpty();
|
|
|
+ $db = new PlatformYouzan();
|
|
|
|
|
|
- if ($rs->isEmpty()) throw new Exception('该商品上线记录不存在');
|
|
|
- if ($rs->exam_status != $db::$exam_status_0) throw new Exception('该商品并不是待审核状态');
|
|
|
+ $rs = $db
|
|
|
+ ->field('a.id,a.spuCode,a.skuCode,a.exam_status,gb.good_name,gb.weight,gb.good_img,gb.cat_id')
|
|
|
+ ->alias('a')
|
|
|
+ ->where(['a.id' => $platform_youzan_id, 'a.is_del' => $db::$del_normal])
|
|
|
+ ->leftJoin('good_basic gb', 'gb.spuCode=a.spuCode')
|
|
|
+ ->findOrEmpty();
|
|
|
|
|
|
- $ladder_info = Db::name('good_ladder')
|
|
|
- ->field('id,min_num,sale_price,cost_fee')
|
|
|
- ->where('id', $data['good_ladder_id'])
|
|
|
- ->where('is_del', 0)
|
|
|
- ->find();
|
|
|
+ if ($rs->isEmpty()) return error_show(1005, '该商品上线记录不存在');
|
|
|
+ if ($rs->exam_status != $db::$exam_status_0) return error_show(1005, '该商品并不是待审核状态');
|
|
|
|
|
|
- if (empty($ladder_info)) throw new Exception('该商品阶梯记录不存在');
|
|
|
+ $ladder_info = Db::name('good_ladder')
|
|
|
+ ->field('id,min_num,sale_price,cost_fee')
|
|
|
+ ->where('id', $data['good_ladder_id'])
|
|
|
+ ->where('is_del', 0)
|
|
|
+ ->find();
|
|
|
|
|
|
- $userinfo = GetUserInfo($data['token']);
|
|
|
+ if (empty($ladder_info)) return error_show(1005, '该商品阶梯记录不存在');
|
|
|
+
|
|
|
+ $userinfo = GetUserInfo($data['token']);
|
|
|
+
|
|
|
+ $update_data = [
|
|
|
+ 'exam_status' => $data['exam_status'],
|
|
|
+ 'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
|
|
|
+ 'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = true;
|
|
|
+
|
|
|
+ if ($data['exam_status'] == $db::$exam_status_1) {
|
|
|
+ //审核通过
|
|
|
+ $update_data = array_merge($update_data, [
|
|
|
+ 'yz_cat_id' => $data['yz_cat_id'],
|
|
|
+ 'is_support_barter' => $data['is_support_barter'],
|
|
|
+ 'sale_price' => $ladder_info['sale_price'],
|
|
|
+ 'cost_fee' => $ladder_info['cost_fee'],
|
|
|
+ 'final_price' => $data['final_price'],
|
|
|
+ 'start_sale_num' => $data['start_sale_num'],
|
|
|
+ 'reject_reason' => '',
|
|
|
+ 'good_ladder_id' => $data['good_ladder_id'],
|
|
|
+ ]);
|
|
|
|
|
|
- $update_data = [
|
|
|
- 'exam_status' => $data['exam_status'],
|
|
|
- 'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
|
|
|
- 'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
|
|
|
- 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+ //调有赞项目的接口,从有赞平台下线该商品
|
|
|
+ $curl_data = [
|
|
|
+ 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
|
|
|
+ 'item_type' => 0,//0实物商品
|
|
|
+ 'title' => $rs->good_name,//商品标题
|
|
|
+ 'is_support_barter' => $data['is_support_barter'],//是否支持换货。1:支持;0:不支持
|
|
|
+ 'desc' => '我是商品描述',//商品描述
|
|
|
+ 'item_weight' => $rs->weight,
|
|
|
+ 'category_id' => $rs->cat_id,
|
|
|
+ 'auto_listing_time' => '0',//0立即售出,传值表示定时(要大于当前时间戳)
|
|
|
+ 'stock_deduct_mode' => 0,//0拍下减库存
|
|
|
+ 'is_display' => 1,//1上架商品
|
|
|
+ 'quantity' => '1111111111',//库存数,先随便写个数,待 @戴 确定
|
|
|
+ 'hide_stock' => 0,//0显示库存,1不显示库存
|
|
|
+ 'origin' => $ladder_info['sale_price'],//系统售价
|
|
|
+ 'price' => $data['final_price'],//最后售价
|
|
|
+ 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
|
|
|
+ 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
|
|
|
+ 'good_img' => $rs->good_img,//图片集合
|
|
|
+ 'post_fee' => 0,//运费,单位分,整数
|
|
|
+ 'sell_point' => '',//商品卖点信息
|
|
|
+ 'yz_cat_id' => $data['yz_cat_id'],//有赞类目id
|
|
|
+ 'start_sale_num' => $data['start_sale_num'],//商品起售数,默认为1
|
|
|
];
|
|
|
-
|
|
|
- if ($data['exam_status'] == $db::$exam_status_1) {
|
|
|
- //审核通过
|
|
|
- $update_data = array_merge($update_data, [
|
|
|
- 'yz_cat_id' => $data['yz_cat_id'],
|
|
|
- 'is_support_barter' => $data['is_support_barter'],
|
|
|
- 'sale_price' => $ladder_info['sale_price'],
|
|
|
- 'cost_fee' => $ladder_info['cost_fee'],
|
|
|
- 'final_price' => $data['final_price'],
|
|
|
- 'start_sale_num' => $data['start_sale_num'],
|
|
|
- 'reject_reason' => '',
|
|
|
- 'good_ladder_id' => $data['good_ladder_id'],
|
|
|
- ]);
|
|
|
-
|
|
|
- //入队列
|
|
|
- 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['is_support_barter'],//是否支持换货。1:支持;0:不支持
|
|
|
- 'desc' => '我是商品描述',//商品描述
|
|
|
- 'item_weight' => $rs->weight,
|
|
|
- 'category_id' => $rs->cat_id,
|
|
|
- 'auto_listing_time' => '0',//0立即售出,传值表示定时(要大于当前时间戳)
|
|
|
- 'stock_deduct_mode' => 0,//0拍下减库存
|
|
|
- 'is_display' => 1,//1上架商品
|
|
|
- 'quantity' => '1111111111',//库存数,先随便写个数,待 @戴 确定
|
|
|
- 'hide_stock' => 0,//0显示库存,1不显示库存
|
|
|
- 'origin' => $ladder_info['sale_price'],//系统售价
|
|
|
- 'price' => $data['final_price'],//最后售价
|
|
|
- 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
|
|
|
- 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
|
|
|
- 'platform_youzan_id' => $platform_youzan_id,
|
|
|
- 'good_img' => $rs->good_img,//图片集合
|
|
|
- 'post_fee' => 0,//运费,单位分,整数
|
|
|
- 'sell_point' => '',//商品卖点信息
|
|
|
- 'yz_cat_id' => $data['yz_cat_id'],//有赞类目id
|
|
|
- 'start_sale_num' => $data['start_sale_num'],//商品起售数,默认为1
|
|
|
- ]));
|
|
|
+ $host = config('app.yz_domain');
|
|
|
+ $response = curl_request($host . 'api/yz_goodup', $curl_data);
|
|
|
+ $response = json_decode($response, true);
|
|
|
+
|
|
|
+ if ($response['code'] != 0) {
|
|
|
+ //上架失败
|
|
|
+ $res = false;
|
|
|
+ $update_data = array_merge($update_data, ['exam_status' => $db::$exam_status_7, 'offline_fail_reason' => $response['message']]);
|
|
|
} else {
|
|
|
- $update_data = array_merge($update_data, ['reject_reason' => $data['reject_reason']]);
|
|
|
+ //上架成功
|
|
|
+ $update_data = array_merge($update_data, ['exam_status' => $db::$exam_status_6, 'offline_fail_reason' => '', 'plat_code' => $response['data']['plat_code']]);
|
|
|
}
|
|
|
|
|
|
- //更新
|
|
|
- $db->where('id', $platform_youzan_id)
|
|
|
- ->where('exam_status', '=', $db::$exam_status_0)
|
|
|
- ->save($update_data);
|
|
|
+ } else $update_data['reject_reason'] = $data['reject_reason'];
|
|
|
|
|
|
- Db::commit();
|
|
|
|
|
|
- return app_show(0, '操作成功');
|
|
|
+ //更新
|
|
|
+ $db->where('id', $platform_youzan_id)
|
|
|
+ ->where('exam_status', '=', $db::$exam_status_0)
|
|
|
+ ->save($update_data);
|
|
|
|
|
|
- } catch (Exception $exception) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1005, $exception->getMessage());
|
|
|
- }
|
|
|
+ return $res ? app_show(0, '操作成功') : error_show(1005, '上架失败,' . $response['message']);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -379,7 +376,7 @@ class Goodup
|
|
|
}
|
|
|
|
|
|
|
|
|
- //添加商品下线到处理队列中
|
|
|
+ //有赞商品下线
|
|
|
public static function youzanGoodOffline(int $platform_youzan_id = 0, array $data = [])
|
|
|
{
|
|
|
|
|
@@ -399,13 +396,27 @@ class Goodup
|
|
|
|
|
|
$userinfo = GetUserInfo($data['token']);
|
|
|
|
|
|
- //入队列
|
|
|
- Cache::store("redis")->handler()->lPush(self::$redis_good_offline_key, json_encode([
|
|
|
+ $curl_data = [
|
|
|
'item_no' => $rs->skuCode,//商品自定义编码 skuCode
|
|
|
'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
|
|
|
'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
|
|
|
- 'platform_youzan_id' => $platform_youzan_id,
|
|
|
- ]));
|
|
|
+ ];
|
|
|
+
|
|
|
+ //调有赞项目的接口,从有赞平台下线该商品
|
|
|
+ $host = config('app.yz_domain');
|
|
|
+ $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
|
|
|
+
|
|
|
+ $response = json_decode($response, true);
|
|
|
+
|
|
|
+ if ($response['code'] != 0) throw new Exception($response['message']);
|
|
|
+
|
|
|
+ $db::where('id', $platform_youzan_id)
|
|
|
+ ->update([
|
|
|
+ 'exam_status' => $db::$exam_status_8,
|
|
|
+ 'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
|
|
|
+ 'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
|
|
|
+ 'updatetime' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
|
|
|
Db::commit();
|
|
|
|