Goodup.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. namespace app\youzan\logic;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use app\youzan\model\PlatformYouzan;
  6. use think\Exception;
  7. use think\facade\Cache;
  8. use think\facade\Db;
  9. //商品处理层
  10. class Goodup
  11. {
  12. //提交商品上线
  13. public static function create(array $data = [])
  14. {
  15. $isonline = [];
  16. $i = 0;
  17. Db::startTrans();
  18. try {
  19. $all_list = Db::name("platform_youzan")
  20. ->where(["platform_id" => $data['platform_id'], "is_del" => PlatformYouzan::$del_normal])
  21. ->whereIn('spuCode', array_column($data['good_data'], 'spuCode'))
  22. ->column('id,exam_status', 'spuCode');
  23. foreach ($data['good_data'] as $value) {
  24. // $count = Db::name("good_nake")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->count();
  25. $ist = isset($all_list[$value['spuCode']]) ? $all_list[$value['spuCode']] : [];
  26. if ($ist) {
  27. $god = Db::name("good_basic")
  28. ->field('id,good_name,good_thumb_img')
  29. ->where(["spuCode" => $value['spuCode'], "is_del" => 0])
  30. ->find();
  31. if ($god) {
  32. $tp = [];
  33. $tp['spuCode'] = $value['spuCode'];
  34. $tp['good_name'] = $god['good_name'];
  35. $tp['good_img'] = $god['good_thumb_img'];
  36. $tp['exam_status'] = $ist['exam_status'];
  37. $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  38. $speclist = [];
  39. if (!empty($spec)) {
  40. foreach ($spec as $val) {
  41. $temp = [];
  42. $temp['id'] = $val['id'];
  43. $temp['spuCode'] = $val['spuCode'];
  44. $temp['spec_id'] = $val['spec_id'];
  45. $temp['spec_value_id'] = $val['spec_value_id'];
  46. $temp['is_del'] = $val['is_del'];
  47. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  48. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  49. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  50. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  51. $speclist[] = $temp;
  52. }
  53. }
  54. $tp["speclist"] = empty($speclist) ? [] : $speclist;
  55. $isonline[] = $tp;
  56. }
  57. }
  58. if (!empty($isonline)) {
  59. return app_show(1009, "存在已上线产品", $isonline);
  60. }
  61. //改变编码规则,将原来的skuCode后两位换成序列号
  62. //str_pad字符串填充
  63. $skuCode = makeNo("SN");
  64. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  65. $tmp = [
  66. "platform_id" => $data['platform_id'],
  67. "online_reason" => $data['online_reason'],
  68. "online_remark" => $data['online_remark'],
  69. "spuCode" => $value['spuCode'],
  70. "skuCode" => $skuCode,
  71. "exam_status" => PlatformYouzan::$exam_status_0,
  72. "is_del" => PlatformYouzan::$del_normal,
  73. "createrid" => $data['createrid'],
  74. "creater" => $data['creater'],
  75. "updaterid" => $data['createrid'],
  76. "updater" => $data['creater'],
  77. "addtime" => date("Y-m-d H:i:s"),
  78. "updatetime" => date("Y-m-d H:i:s")
  79. ];
  80. $i++;
  81. //修改状态,添加待办
  82. $create = Db::name("platform_youzan")->insert($tmp, true);
  83. if ($create > 0) {
  84. ActionLog::logAdd(['id' => $data['createrid'], 'nickname' => $data['creater']], [
  85. "order_code" => $skuCode,
  86. "status" => $tmp['exam_status'],//这里的status是之前的值
  87. "action_remark" => '',//备注
  88. "action_type" => "create"//新建create,编辑edit,更改状态status
  89. ], "YZSX", $tmp['exam_status'], $tmp);
  90. ProcessOrder::AddProcess(['id' => $data['createrid'], 'nickname' => $data['creater']], [
  91. "order_type" => 'YZSX',
  92. "order_code" => $skuCode,
  93. "order_id" => $create,
  94. "order_status" => $tmp['exam_status'], "before_status" => $tmp['exam_status']
  95. ]);
  96. $iso = Db::name("good")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->find();
  97. if ($iso == false) {
  98. unset($value['id']);
  99. $value['addtime'] = date("Y-m-d H:i:s");
  100. $value['updatetime'] = date("Y-m-d H:i:s");
  101. } else {
  102. $value['id'] = $iso['id'];
  103. $value['updatetime'] = date("Y-m-d H:i:s");
  104. }
  105. $up = Db::name("good")->save($value);
  106. if (!$up) {
  107. Db::rollback();
  108. return error_show(1004, "提交失败");
  109. }
  110. } else {
  111. Db::rollback();
  112. return error_show(1004, "提交失败");
  113. }
  114. }
  115. Db::commit();
  116. return app_show(0, "提交成功");
  117. } catch (\Exception $e) {
  118. Db::rollback();
  119. return error_show(1004, $e->getMessage());
  120. }
  121. }
  122. //审核并将商品推送到有赞平台
  123. public static function youzanGoodUpOnline(int $platform_youzan_id = 0, array $data = [])
  124. {
  125. Db::startTrans();
  126. try {
  127. $db = new PlatformYouzan();
  128. $rs = $db
  129. ->field('a.id,a.spuCode,a.skuCode,a.exam_status,gb.good_name,gb.weight,gb.good_img,gb.cat_id,gb.good_remark')
  130. ->alias('a')
  131. ->where(['a.id' => $platform_youzan_id, 'a.is_del' => $db::$del_normal])
  132. ->leftJoin('good_basic gb', 'gb.spuCode=a.spuCode')
  133. ->findOrEmpty();
  134. if ($rs->isEmpty()) throw new Exception('该商品上线记录不存在');
  135. if ($rs->exam_status != $db::$exam_status_0) throw new Exception('该商品并不是待审核状态');
  136. $old_exam_status = $rs->exam_status;
  137. $userinfo = GetUserInfo($data['token']);
  138. $update_data = [
  139. 'exam_status' => $data['exam_status'],
  140. 'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  141. 'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  142. 'updatetime' => date('Y-m-d H:i:s'),
  143. ];
  144. $res = true;
  145. if ($data['exam_status'] == $db::$exam_status_1) {
  146. $ladder_info = Db::name('good_ladder')
  147. ->field('id,min_num,sale_price,cost_fee')
  148. ->where('id', $data['good_ladder_id'])
  149. ->where('is_del', 0)
  150. ->find();
  151. if (empty($ladder_info)) throw new Exception('该商品阶梯记录不存在');
  152. //运费,单位分,整数
  153. $post_fee = Db::name('good_nake')
  154. ->where(['spuCode' => $rs->spuCode, 'is_del' => 0])
  155. ->where('min_num', '<=', $data['start_sale_num'])
  156. ->value('delivery_fee', 0);
  157. //审核通过
  158. $update_data = array_merge($update_data, [
  159. 'yz_cat_id' => $data['yz_cat_id'],
  160. 'is_support_barter' => $data['is_support_barter'],
  161. 'sale_price' => $ladder_info['sale_price'],
  162. 'cost_fee' => $ladder_info['cost_fee'],
  163. 'final_price' => $data['final_price'],
  164. 'start_sale_num' => $data['start_sale_num'],
  165. 'reject_reason' => '',
  166. 'post_fee' => $post_fee,
  167. 'desc' => $rs->good_remark,//商品描述
  168. 'good_ladder_id' => $data['good_ladder_id'],
  169. 'tags' => implode(',', $data['tags']),
  170. ]);
  171. //调有赞项目的接口,从有赞平台下线该商品
  172. $curl_data = [
  173. 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
  174. 'item_type' => 0,//0实物商品
  175. 'title' => $rs->good_name,//商品标题
  176. 'is_support_barter' => $data['is_support_barter'],//是否支持换货。1:支持;0:不支持
  177. 'desc' => $rs->good_remark,//商品描述
  178. 'item_weight' => $rs->weight,
  179. 'category_id' => $rs->cat_id,
  180. 'auto_listing_time' => '0',//0立即售出,传值表示定时(要大于当前时间戳)
  181. 'stock_deduct_mode' => 0,//0拍下减库存
  182. 'is_display' => 1,//1上架商品
  183. 'quantity' => '1111111111',//库存数,先随便写个数,待 @戴 确定
  184. 'hide_stock' => 0,//0显示库存,1不显示库存
  185. 'origin' => $ladder_info['sale_price'],//系统售价
  186. 'price' => $data['final_price'],//最后售价
  187. 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  188. 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  189. 'good_img' => $rs->good_img,//图片集合
  190. 'post_fee' => $post_fee,//运费,单位分,整数
  191. 'sell_point' => '',//商品卖点信息
  192. 'yz_cat_id' => $data['yz_cat_id'],//有赞类目id
  193. 'start_sale_num' => $data['start_sale_num'],//商品起售数,默认为1
  194. 'tags' => implode(',', $data['tags']),//标签id,多个以,分割
  195. ];
  196. $host = config('app.yz_domain');
  197. $response = curl_request($host . 'api/yz_goodup', $curl_data);
  198. $response = json_decode($response, true);
  199. if ($response['code'] != 0) {
  200. //上架失败
  201. $res = false;
  202. $update_data = array_merge($update_data, ['exam_status' => $db::$exam_status_7, 'offline_fail_reason' => $response['message']]);
  203. } else {
  204. //上架成功
  205. $update_data = array_merge($update_data, ['exam_status' => $db::$exam_status_6, 'offline_fail_reason' => '']);
  206. if ($response['data']['plat_code'] != '') $update_data['plat_code'] = $response['data']['plat_code'];
  207. }
  208. } else $update_data['reject_reason'] = $data['reject_reason'];
  209. //更新
  210. $db->where('id', $platform_youzan_id)
  211. ->where('exam_status', '=', $db::$exam_status_0)
  212. ->save($update_data);
  213. //添加审核记录
  214. //修改状态,添加待办
  215. // 'id' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  216. // 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  217. ActionLog::logAdd([
  218. 'id' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  219. 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : ''
  220. ], [
  221. "order_code" => $rs->skuCode,//编号
  222. "status" => $old_exam_status,
  223. "action_remark" => '',//备注
  224. "action_type" => "status"//新建create,编辑edit,更改状态status
  225. ], 'YZSX', $update_data['exam_status'], $update_data);
  226. ProcessOrder::AddProcess([
  227. 'id' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  228. 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : ''
  229. ], [
  230. "order_type" => 'YZSX',
  231. "order_code" => $rs->skuCode,//咨询单详情编号
  232. "order_id" => $rs->id,
  233. "order_status" => $update_data['exam_status'], "before_status" => $old_exam_status
  234. ]);
  235. if ($res) {
  236. Db::commit();
  237. return app_show(0, '操作成功');
  238. } else throw new Exception('上架失败,' . $response['message']);
  239. } catch (Exception $exception) {
  240. Db::rollback();
  241. return error_show(1005, $exception->getMessage());
  242. }
  243. }
  244. //有赞商品重新上线(上线失败的、下线后又重新上线的)
  245. public static function goodupOnlineAgain(int $platform_youzan_id = 0, string $token = '')
  246. {
  247. $db = new PlatformYouzan();
  248. $rs = $db
  249. ->field('id')
  250. ->where(['id' => $platform_youzan_id, 'is_del' => $db::$del_normal])
  251. ->whereIn('exam_status', [$db::$exam_status_7, $db::$exam_status_8])
  252. ->findOrEmpty();
  253. if ($rs->isEmpty()) return error_show(1005, '该商品上线记录不存在或不允许重新上线');
  254. $userinfo = GetUserInfo($token);
  255. //更新
  256. $res = $db->where('id', $platform_youzan_id)
  257. ->save([
  258. 'exam_status' => $db::$exam_status_0,
  259. 'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  260. 'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  261. 'updatetime' => date('Y-m-d H:i:s'),
  262. ]);
  263. return $res ? app_show(0, '操作成功') : error_show(1005, '重新发起上线失败');
  264. }
  265. //商品上线详情
  266. public static function getYzGoodupInfo(int $platform_youzan_id = 0)
  267. {
  268. $data = Db::name('platform_youzan')
  269. ->where('id', $platform_youzan_id)
  270. ->find();
  271. if (empty($data)) return error_show(1005, '查询不到该记录');
  272. $good_data = Db::name("good_basic")
  273. ->withoutField('createrid,creater,is_del,addtime,updatetime')
  274. ->where(["is_del" => 0, "spuCode" => $data['spuCode']])
  275. ->find();
  276. if ($good_data == false) return error_show(1004, "未找到商品数据");
  277. $data = array_merge($data, $good_data);
  278. $plat = Db::name("platform")->where(["id" => $data['platform_id']])->find();
  279. // $data['skuCode'] = $data['skuCode'];
  280. $data['platform_code'] = $data['platform_id'];
  281. $data['platform_code_en'] = isset($plat['platform_code']) ? $plat['platform_code'] : "";
  282. $data['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  283. // $data['online_reason'] = $good_platform['online_reason'];
  284. // $data['online_time'] = $data['online_time'];
  285. // $data['online_remark'] = $good_platform['online_remark'];
  286. // $data['exam_status'] = $good_platform['exam_status'];
  287. // $data['is_online'] = $good_platform['is_online'];
  288. // $data['plat_code'] = $data['plat_code'];
  289. // $data['exclusive'] = makeExcluse($data['is_exclusive']);
  290. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  291. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  292. $data['cat_info'] = made($data['cat_id'], []);
  293. $data['yz_cat_info'] = made_youzan($data['yz_cat_id'], []);
  294. $spec = Db::name("good_spec")->where(["spuCode" => $data['spuCode'], "is_del" => 0])->select()->toArray();
  295. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  296. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  297. // $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $this->noble[$data['noble_metal']] : "";
  298. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  299. $data['company'] = isset($company['company']) ? $company['company'] : "";
  300. if ($data['brand_id'] != 0) {
  301. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  302. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  303. } else {
  304. $data["brand_name"] = "";
  305. $data["brand_id"] = "";
  306. }
  307. $data['origin_place_cn'] = "";
  308. $data['delivery_place_cn'] = "";
  309. if ($data['delivery_place'] !== "") {
  310. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  311. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['delivery_place']);
  312. $data['delivery_place_cn'] = GetAddr(json_encode($place));
  313. }
  314. if ($data['origin_place'] !== "") {
  315. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  316. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['origin_place']);
  317. $data['origin_place_cn'] = GetAddr(json_encode($place));
  318. }
  319. $excluse = makeExcluse($data['is_exclusive']);
  320. $data['exclusive'] = $excluse;
  321. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : [];
  322. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  323. $speclist = [];
  324. if (!empty($spec)) {
  325. foreach ($spec as $value) {
  326. $temp = [];
  327. $temp['id'] = $value['id'];
  328. $temp['spuCode'] = $value['spuCode'];
  329. $temp['spec_id'] = $value['spec_id'];
  330. $temp['spec_value_id'] = $value['spec_value_id'];
  331. $temp['is_del'] = $value['is_del'];
  332. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  333. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  334. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  335. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  336. $speclist[] = $temp;
  337. }
  338. }
  339. $data["speclist"] = empty($speclist) ? [] : $speclist;
  340. $ladder = Db::name("good_ladder")->where(['skuCode' => $data['skuCode'], "is_del" => 0])->select()->toArray();
  341. $data["ladderlist"] = !empty($ladder) ? $ladder : [];
  342. $nakelist = Db::name("good_nake")->where(['spuCode' => $data['spuCode'], "is_del" => 0])->select()->toArray();
  343. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  344. // $cat_top_list = $data['yz_cat_info'];
  345. // $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  346. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  347. $gold_price = 0;
  348. if ($data['is_gold_price'] == 1 && $data['cost_fee'] != 0 && $data['good_price'] == 0) {
  349. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  350. }
  351. $data['gold_price'] = $gold_price;
  352. $nakearry = [];
  353. if (!empty($nakelist)) {
  354. //实时金价
  355. foreach ($nakelist as $value) {
  356. $value['sale_price'] = $value['nake_total'];
  357. //计算最终售价
  358. if ($data['is_gold_price'] == 1 && $data['cost_fee'] != 0 && $data['good_price'] == 0) {
  359. //普通商品:直接用财务提交的售价字段;
  360. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  361. $value['sale_price'] = ($data['weight'] * $gold_price + $value['cost_fee'] * $data['weight'] + $value['package_fee'] + $value['mark_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['other_fee']);
  362. }
  363. $nakearry[] = $value;
  364. }
  365. }
  366. $proof = Db::name("good_proof")->where(["spuCode" => $data['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  367. $data['proof'] = isset($proof) && $proof != false ? $proof : [];
  368. $data["nakelist"] = $nakearry;
  369. //补充采购员字段
  370. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  371. $temp_basic_info = Db::name('good_basic')
  372. ->field('id,createrid purchase_id,creater purchase')
  373. ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
  374. ->find();
  375. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  376. $data['purchase'] = $temp_basic_info['purchase'];
  377. return app_show(0, "获取成功", $data);
  378. }
  379. //有赞商品下线
  380. public static function youzanGoodOffline(int $platform_youzan_id = 0, array $data = [])
  381. {
  382. Db::startTrans();
  383. try {
  384. $db = new PlatformYouzan();
  385. $rs = $db
  386. ->field('id,skuCode,exam_status')
  387. ->where(['id' => $platform_youzan_id, 'is_del' => $db::$del_normal])
  388. ->findOrEmpty();
  389. if ($rs->isEmpty()) throw new Exception('该记录不存在');
  390. if ($rs->exam_status == $db::$exam_status_8) throw new Exception('该商品已下线,无法重复下线');
  391. $userinfo = GetUserInfo($data['token']);
  392. $curl_data = [
  393. 'item_no' => $rs->skuCode,//商品自定义编码 skuCode
  394. 'uid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  395. 'nickname' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  396. ];
  397. if ($rs->exam_status == $db::$exam_status_6) {
  398. //已上线的要调用有赞接口下线
  399. //调有赞项目的接口,从有赞平台下线该商品
  400. $host = config('app.yz_domain');
  401. $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
  402. $response = json_decode($response, true);
  403. if ($response['code'] != 0) throw new Exception($response['message']);
  404. }
  405. $db::where('id', $platform_youzan_id)
  406. ->update([
  407. 'exam_status' => $db::$exam_status_8,
  408. 'offline_reason_id' => $data['offline_reason_id'],
  409. 'offline_remark' => $data['offline_remark'],
  410. 'updaterid' => isset($userinfo['data']['id']) ? $userinfo['data']['id'] : 0,
  411. 'updater' => isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : '',
  412. 'updatetime' => date('Y-m-d H:i:s')
  413. ]);
  414. Db::commit();
  415. return app_show(0, '操作成功');
  416. } catch (Exception $exception) {
  417. Db::rollback();
  418. return error_show(1005, $exception->getMessage());
  419. }
  420. }
  421. //有赞下线商品列表
  422. public static function youzanOfflineList(array $data = [])
  423. {
  424. $where = [['pyz.exam_status', '=', PlatformYouzan::$exam_status_8], ['pyz.is_del', '=', PlatformYouzan::$del_normal]];//已下线
  425. if ($data['start_date'] != '' && $data['end_date'] != '') $where[] = ['pyz.addtime', 'between', [$data['start_date'], $data['end_date']]];
  426. if ($data['creater'] != '') $where[] = ['pyz.creater', 'like', '%' . $data['creater'] . '%'];
  427. $count = Db::name('platform_youzan')
  428. ->alias('pyz')
  429. ->leftJoin('good g', 'g.spuCode=pyz.spuCode')
  430. ->where($where)
  431. ->count('pyz.id');
  432. $list = PlatformYouzan::field('pyz.id,pyz.id platform_youzan_id,pyz.spuCode,g.good_name,pyz.updater,pyz.updatetime')
  433. ->alias('pyz')
  434. ->leftJoin('good g', 'g.spuCode=pyz.spuCode')
  435. ->where($where)
  436. ->order('pyz.addtime', 'desc')
  437. ->page($data['page'], $data['size'])
  438. ->select()
  439. ->toArray();
  440. return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  441. }
  442. //有赞下线商品详情
  443. public static function youzanOfflineDetail(int $platform_youzan_id = 0)
  444. {
  445. $info = PlatformYouzan::where('pyz.id', $platform_youzan_id)
  446. ->field('pyz.*,g.good_name,r.result,p.platform_name')
  447. ->alias('pyz')
  448. ->leftJoin('good g', 'g.spuCode=pyz.spuCode')
  449. ->leftJoin('result_info r', 'r.result_code=pyz.offline_reason_id')
  450. ->leftJoin('platform p', 'p.id=pyz.platform_id')
  451. ->findOrEmpty();
  452. return app_show(0, "获取成功", $info);
  453. }
  454. }