Good.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\txx\controller;
  4. use app\BaseController;
  5. use app\txx\model\Act;
  6. use app\txx\model\ActGood;
  7. use app\txx\model\YzGood;
  8. use app\txx\model\PlatformYouzan;
  9. use think\App;
  10. use think\Exception;
  11. use think\facade\Db;
  12. use think\facade\Validate;
  13. use think\Request;
  14. class Good extends BaseController
  15. {
  16. protected $uid=0;
  17. protected $uname='';
  18. protected $platformid=[37,79];
  19. /**@param array snArr 商品编号sn数组
  20. * @param string actCode 活动编号
  21. * @return \think\response\Json
  22. * @throws \think\exception\DbException
  23. */
  24. private $acton=[];
  25. public $noble=[];
  26. public $origin_img_host ="http://stock.api.wanyuhengtong.com";
  27. public $ssl_img_host ="https://image.wanyuhengtong.com";
  28. public function __construct(App $app) {
  29. parent::__construct($app);
  30. if($this->request->isCx==1){
  31. $this->uid=$this->request->uid;
  32. $this->uname=$this->request->uname;
  33. }
  34. }
  35. public function AddGood()
  36. {
  37. $post = $this->request->only(["snArr"=>[],"actCode"=>''],"post","trim");
  38. $snArr= $post['snArr'];
  39. if(empty($snArr)) return json_show(1004,"参数错误 snArr 不能为空");
  40. $platformYouzan =new PlatformYouzan();
  41. $skuCodes = array_column($snArr,"skuCode");
  42. $goodArr = $platformYouzan->where(["skuCode"=>$skuCodes,"is_del"=>0])->select()->toArray();
  43. if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
  44. $goodArr = array_column($goodArr,"skuCode");
  45. $actCode= $post['actCode']!=''? trim($post['actCode']):"";
  46. if($actCode=='') return json_show(1004,"参数错误 actCode 不能为空");
  47. $act =new Act();
  48. $isActExit=$act->where(['actCode'=>$actCode,"is_del"=>0])->find();
  49. if($isActExit->isEmpty()) return json_show(1005,"未找到活动有效数据");
  50. $actGood=new ActGood();
  51. Db::startTrans();
  52. try{
  53. $data=[];
  54. foreach ($snArr as $item){
  55. if(!in_array($item['skuCode'],$goodArr)) throw new Exception("商品编号{$item['skuCode']}不存在",1006);
  56. $isExit = $actGood->where(['actCode'=>$actCode,'yz_good_code'=>$item['skuCode'],'roundId'=>$item['roundId']??'','is_del'=>0])->findOrEmpty();
  57. if(!$isExit->isEmpty()) throw new Exception("活动商品已添加",1006);
  58. $temp=[
  59. "actCode"=>$actCode,
  60. "yz_good_code"=>$item['skuCode'],
  61. "stock_num"=>$item['stock_num'],
  62. "used_num"=>0,
  63. "balance_num"=>$item['stock_num'],
  64. "apply_id"=>$this->uid,
  65. "apply_name"=>$this->uname,
  66. "roundId"=>$item['roundId']??"",
  67. "version"=>"2.0",
  68. "status"=>1,
  69. "addtime"=>date("Y-m-d H:i:s"),
  70. "updatetime"=>date("Y-m-d H:i:s")
  71. ];
  72. $data[]=$temp;
  73. }
  74. if (empty($data)){
  75. throw new Exception("活动商品不能为空",1006);
  76. }
  77. $isAdd=$actGood->saveAll($data);
  78. if ($isAdd->isEmpty())throw new Exception("活动商品添加失败",1006);
  79. $up =$act->where($isActExit->toArray())->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  80. if ($up==false){
  81. throw new Exception("活动商品添加失败",1006);
  82. }
  83. Db::commit();
  84. }catch (\Exception $e){
  85. Db::rollback();
  86. return json_show(1008,$e->getMessage());
  87. }
  88. return json_show(0,'活动商品添加成功');
  89. }
  90. /**活动商品列表
  91. * @param int page 页数
  92. * @param int size 每页显示数量
  93. * @param string act_name 活动名称
  94. * @param string actCode 活动编号
  95. * @param string company_name 活动公司名称
  96. * @param string contactor 活动联系人
  97. * @param int act_type 活动类型 暂无
  98. * @param int cat_id 采销分类
  99. * @param string spuCode 商品成本编号
  100. * @param string skuCode 商品上线编号
  101. * @param int exam_status 商品上线审核状态
  102. */
  103. public function list()
  104. {
  105. $param = $this->request->only([
  106. "page"=>1,
  107. "size"=>15,
  108. "act_name"=>'',
  109. "actCode"=>'',
  110. "company_name"=>'',
  111. "contactor"=>'',
  112. "act_type"=>'',
  113. "good_name"=>'',
  114. "cat_id"=>'',
  115. "spuCode"=>'',
  116. "skuCode"=>'',
  117. "status"=>"",
  118. "roundId"=>"",
  119. "exam_status"=>'',
  120. ],"post",'trim');
  121. $condition=[["a.is_del","=",0],["b.is_del","=",0]];
  122. if($param['act_name']!='') $condition[]=["b.act_name","like","%{$param['act_name']}%"];
  123. if($param['actCode']!='') $condition[]=["a.actCode","like","%{$param['actCode']}%"];
  124. if($param['company_name']!='') $condition[]=["b.company_name","like","%{$param['company_name']}%"];
  125. if($param['contactor']!='') $condition[]=["b.contactor","like","%{$param['contactor']}%"];
  126. if($param['good_name']!='') $condition[]=["d.good_name","like","%{$param['good_name']}%"];
  127. if($param['skuCode']!='') $condition[]=["c.skuCode","like","%{$param['skuCode']}%"];
  128. if($param['act_type']!='') $condition[]=["b.act_type","=",$param["act_type"]];
  129. if($param['roundId']!=='') $condition[]=["a.roundId","=",$param["roundId"]];
  130. if($param['status']!=='') $condition[]=["a.status","=",$param["status"]];
  131. if ($param['exam_status'] !== '') {
  132. if($param['exam_status']==1){
  133. $where[] = ['c.exam_status', "=", 6];
  134. }else{
  135. $where[] = ['c.exam_status', "<>", 6];
  136. }
  137. }
  138. $actm=new ActGood();
  139. if($this->request->isCx==1){
  140. $field="a.id,a.actCode,a.yz_good_code,a.apply_id,a.apply_name,a.stock_num,a.used_num,a.balance_num,a.status,
  141. a.addtime,a.updatetime,c.plat_code,b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,
  142. c.final_price,c.desc,d.good_name,d.good_unit,c.yz_cat_id,d.cat_id,a.roundId,d.brand_id,a.roundId,a.promocode_id";
  143. }else{
  144. $field="a.id,a.actCode,a.yz_good_code,a.stock_num,a.used_num,a.balance_num,a.status,a.addtime,a.updatetime,
  145. b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,c.final_price,c.desc,d.good_name,
  146. d.good_unit,d.cat_id,d.brand_id,a.roundId,a.promocode_id";
  147. }
  148. $count =$actm->alias("a")
  149. ->leftJoin("act b","a.actCode=b.actCode")
  150. ->leftJoin("platform_youzan c","a.yz_good_code=c.skuCode")
  151. ->leftJoin("good d","c.spuCode=d.spuCode")
  152. ->where($condition)->count();
  153. $total =ceil($count/$param['size']);
  154. $page = $param['page']>= $total ?intval($total):intval($param['page']);
  155. $list=$actm->alias("a")
  156. ->leftJoin("act b","a.actCode=b.actCode")
  157. ->leftJoin("platform_youzan c","a.yz_good_code=c.skuCode")
  158. ->leftJoin("good d","c.spuCode=d.spuCode")
  159. ->field($field)->where($condition)->page($page,intval($param['size']))
  160. ->order("addtime desc")->select()->toArray();
  161. //6.补充数据,照搬list方法
  162. $all_brand = Db::name('brand')
  163. ->where('is_del', 0)
  164. ->whereIn('id', array_column($list, 'brand_id'))
  165. ->column('brand_name', 'id');
  166. $unit = Db::name("unit")->where(["id" => array_column($list, 'good_unit')])->column('unit', 'id');
  167. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  168. $yzgood =new YzGood();
  169. foreach ($list as &$item){
  170. $item['unit'] =$unit[$item['good_unit']] ?? "";
  171. $item['brand_name'] = $all_brand[$item['brand_id']]?? "";
  172. $item['web_url_num'] = Db::name("act_goodurl")->where(["act_good_id"=>$item['id'],"is_del"=>0])->count();
  173. $item['origin_price'] =$yzgood->where(["item_no"=>$item['yz_good_code'],"is_del"=>0])->value("origin",'');
  174. if($this->request->isCx==1){
  175. $item['cat_info'] = made($item['cat_id'], []);
  176. }else{
  177. unset($item['cat_id']);
  178. unset($item['good_unit']);
  179. unset($item['brand_id']);
  180. }
  181. }
  182. return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  183. }
  184. /**
  185. * 保存新建的资源
  186. *
  187. * @param \think\Request $request
  188. * @return \think\Response
  189. */
  190. public function EditGood()
  191. {
  192. $post = $this->request->only(["goodArr"=>[]],"post");
  193. $snArr= $post['goodArr'];
  194. if(empty($snArr)) return json_show(1004,"参数 goodArr 不能为空");
  195. $platformYouzan =new PlatformYouzan();
  196. $goodCode = array_column($snArr,"yz_good_code");
  197. $goodArr = $platformYouzan->where(["skuCode"=>$goodCode,"is_del"=>0])->select()->toArray();
  198. if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
  199. $actGood=new ActGood();
  200. Db::startTrans();
  201. try{
  202. $data=[];
  203. foreach ($snArr as $item){
  204. $isExit = $actGood->where(["actCode"=>$item['actCode'],"yz_good_code"=>$item['yz_good_code'],
  205. "is_del"=>0])->findOrEmpty();
  206. if($isExit->isEmpty()) throw new Exception("活动商品不存在",1006);
  207. $temp=[
  208. "id"=>$isExit['id'],
  209. "stock_num"=>$item['stock_num'],
  210. "balance_num"=>$item['stock_num'],
  211. "roundId"=>$item['roundId']??"",
  212. "is_del"=>$item['is_del']??0,
  213. "updatetime"=>date("Y-m-d H:i:s")
  214. ];
  215. $data[]=$temp;
  216. }
  217. $isAdd=$actGood->saveAll($data);
  218. if ($isAdd==false)throw new Exception("活动商品更新失败",1006);
  219. Db::commit();
  220. return json_show(0,"活动商品更新成功");
  221. }catch (\Exception $e){
  222. Db::rollback();
  223. return json_show(1008,$e->getMessage());
  224. }
  225. }
  226. /**
  227. * 显示指定的资源
  228. *
  229. * @param int $id 参数详情id
  230. * @return \think\Response
  231. */
  232. public function GoodInfo()
  233. {
  234. $param =$this->request->only(["id"=>''],"post","trim");
  235. if($param['id']=='') return json_show(1004,"参数 id 不能为空");
  236. if($this->request->isCx==1){
  237. $field="a.id,a.actCode,a.yz_good_code,a.apply_id,a.apply_name,a.stock_num,a.used_num,a.balance_num,a.status,
  238. a.addtime,a.updatetime,c.plat_code,b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,
  239. c.final_price,c.desc,d.good_name,d.good_unit,c.yz_cat_id,d.cat_id,d.brand_id,a.roundId";
  240. }else{
  241. $field="a.id,a.actCode,a.yz_good_code,a.stock_num,a.used_num,a.balance_num,a.status,a.addtime,a.updatetime,
  242. b.act_name,b.company_name,b.contactor,b.mobile,b.startTime,b.endTime,c.final_price,c.desc,d.good_name,
  243. d.good_unit,d.cat_id,d.brand_id,a.roundId";
  244. }
  245. $actm=new ActGood();
  246. $info=$actm->alias("a")
  247. ->leftJoin("act b","a.actCode=b.actCode")
  248. ->leftJoin("platform_youzan c","a.yz_good_code=c.skuCode")
  249. ->leftJoin("good d","c.spuCode=d.spuCode")
  250. ->field($field)
  251. ->find($param);
  252. if($info==false){
  253. return json_show(1005,"未找到数据");
  254. }
  255. $info['brand_name'] = Db::name('brand')
  256. ->where('is_del', 0)
  257. ->where('id',$info['brand_id'])
  258. ->value('brand_name', '');
  259. $info['unit'] = Db::name("unit")->where("id" ,$info['good_unit'])->value('unit', '');
  260. if($this->request->isCx==1){
  261. $info['cat_info'] =made($info['cat_id']);
  262. }else{
  263. unset($info['good_unit']);
  264. unset($info['brand_id']);
  265. }
  266. return json_show(0,"获取成功",$info->toArray());
  267. }
  268. /** 商品链接导入
  269. * @param int act_good_id 商品活动id
  270. * @param array web_url 商品链接url
  271. * @return \think\Response
  272. */
  273. public function GoodUrlImport()
  274. {
  275. $param = $this->request->only(["web_url"=>[]],"post");
  276. $validate=Validate::rule([
  277. 'web_url|商品链接' => 'require|array'
  278. ]);
  279. if($validate->check($param)==false) return json_show(1004,$validate->getError());
  280. $actm=new ActGood();
  281. $web=[];
  282. foreach ($param['web_url'] as $item){
  283. $actGood =$actm->where(["id"=>$item['act_good_id'],"is_del"=>0])->find();
  284. if($actGood==false) return json_show(1005,'未找到商品数据');
  285. $temp=[
  286. "act_good_url"=>$item['act_good_url'],
  287. "act_good_id"=>$item['act_good_id'],
  288. "status"=>1,
  289. "is_del"=>0,
  290. "apply_id"=>$this->uid,
  291. "apply_name"=>$this->uname,
  292. "addtime"=>date("Y-m-d H:i:s"),
  293. "updatetime"=>date("Y-m-d H:i:s")
  294. ];
  295. $web[]=$temp;
  296. }
  297. Db::startTrans();
  298. try{
  299. $isAdd=Db::name("act_goodurl")->insertAll($web);
  300. if( $isAdd<=0 ){
  301. Db::rollback();
  302. return json_show(1006,"商品链接导入失败");
  303. }
  304. $ids = array_unique(array_column($param['web_url'],"act_good_id"));
  305. foreach ($ids as $item){
  306. $actGood =$actm->where(["id"=>$item,"is_del"=>0])->find();
  307. if($actGood==false)throw new Exception("未找到活动商品",1006);
  308. $num =Db::name("act_goodurl")->where(["act_good_id"=>$item,"is_del"=>0])->count();
  309. if($num>$actGood['stock_num'])throw new Exception("导入连接数量超过活动数量",1006);
  310. if($num==$actGood['stock_num']){
  311. $up =$actm->where(["id"=>$item,"is_del"=>0])->update(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  312. if($up==false) return json_show(1005,'商品数据更新失败');
  313. $upunum = $actm->where(["actCode"=>$actGood["actCode"],"is_del"=>0,"status"=>0])->count();
  314. if($upunum==0){
  315. $up1 =Db::name("Act")->where(["actCode"=>$actGood["actCode"],"is_del"=>0])->update(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  316. if ($up1==false){
  317. throw new Exception("活动数据更新失败",1006);
  318. }
  319. }
  320. }
  321. }
  322. Db::commit();
  323. return json_show(0,'商品链接导入成功');
  324. }catch (\Exception $e){
  325. Db::rollback();
  326. return json_show(1008,$e->getMessage());
  327. }
  328. }
  329. /**
  330. * 保存更新的资源
  331. * @param int $page
  332. * @param int $size
  333. * @param string $act_name
  334. * @param string $actCode
  335. * @param int $act_good_id
  336. * @return \think\Response
  337. */
  338. public function GoodUrlList()
  339. {
  340. $param = $this->request->only([
  341. "page"=>1,
  342. "size"=>15,
  343. "act_name"=>'',
  344. "actCode"=>'',
  345. "act_good_id"=>'',
  346. "good_code"=>'',
  347. "roundId"=>'',
  348. ],"post","trim");
  349. $condition=[["a.is_del","=",0],["b.is_del","=",0],["c.is_del","=",0]];
  350. if($param['act_name']!='')$condition[]=["c.act_name","like","%{$param['act_name']}%"];
  351. if($param['actCode']!='')$condition[]=["c.actCode","like","%{$param['actCode']}%"];
  352. if($param['act_good_id']!='')$condition[]=["a.act_good_id","=",$param['act_good_id']];
  353. if($param['good_code']!='')$condition[]=["b.yz_good_code","=",$param['good_code']];
  354. if($param['roundId']!=='') $condition[]=["b.roundId","=",$param["roundId"]];
  355. $count = Db::name("act_goodurl")->alias("a")
  356. ->leftJoin("act_good b","a.act_good_id=b.id and b.is_del=0")
  357. ->leftJoin("act c","b.actCode=c.actCode and c.is_del=0")
  358. ->where($condition)
  359. ->count();
  360. $total =ceil($count/$param['size']);
  361. $page =$param['page']>=$total ? intval($total) : intval($param['page']);
  362. $list = Db::name("act_goodurl")->alias("a")
  363. ->leftJoin("act_good b","a.act_good_id=b.id and b.is_del=0")
  364. ->leftJoin("act c","b.actCode=c.actCode and c.is_del=0")
  365. ->where($condition)->page($page,intval($param['size']))
  366. ->field("a.id,a.act_good_url,b.roundId,a.act_good_id,a.apply_id,a.apply_name,a.addtime,a.updatetime,b.stock_num")
  367. ->select()->toArray();
  368. foreach ($list as &$item){
  369. $item['web_url_num'] = Db::name("act_goodurl")->where(["act_good_id"=>$item['act_good_id'],"is_del"=>0])->count();
  370. }
  371. return json_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  372. }
  373. /**
  374. * 删除指定资源
  375. *
  376. * @param int $id
  377. * @return \think\Response
  378. */
  379. public function GoodUrlDel()
  380. {
  381. $param = $this->request->only(["web_url_ids"=>[]],"post");
  382. if(empty($param['web_url_ids'])|| $param["web_url_ids"]=="") return json_show(1004,"参数 web_url_ids 不能为空");
  383. $actm=new ActGood();
  384. $web=[];
  385. foreach ($param['web_url_ids'] as $item){
  386. $actGood =Db::name("act_goodurl")->where(["id"=>$item,"is_del"=>0])->find();
  387. if($actGood==false) return json_show(1005,'未找到商品链接数据');
  388. $web[]=$actGood['act_good_id'];
  389. }
  390. $web =array_unique($web);
  391. Db::startTrans();
  392. try{
  393. $isDel=Db::name("act_goodurl")->where(["id"=>$param['web_url_ids']])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  394. if($isDel==false){
  395. throw new Exception("活动商品链接删除失败",1006);
  396. }
  397. foreach ($web as $item){
  398. $actGood =$actm->where(["id"=>$item,"is_del"=>0])->find();
  399. if($actGood==false) return json_show(1005,'未找到商品数据');
  400. $num =Db::name("act_goodurl")->where(["act_good_id"=>$item,"is_del"=>0])->count();
  401. if($num<$actGood['stock_num']){
  402. $up =$actm->where(["id"=>$item,"is_del"=>0])->update(["status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  403. if($up==false) return json_show(1005,'商品数据更新失败');
  404. $upunum = $actm->where(["actCode"=>$actGood["actCode"],"is_del"=>0,"status"=>0])->count();
  405. if($upunum!=0){
  406. $up1 =Db::name("Act")->where(["actCode"=>$actGood["actCode"],"is_del"=>0])->update(["status"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  407. if ($up1==false){
  408. throw new Exception("活动数据更新失败",1006);
  409. }
  410. }
  411. }
  412. }
  413. Db::commit();
  414. return json_show(0,'商品链接导入成功');
  415. }catch (\Exception $e){
  416. Db::rollback();
  417. return json_show(1008,$e->getMessage());
  418. }
  419. }
  420. //获取跟有赞对接的平台所属的商品上线信息
  421. public function listByYz()
  422. {
  423. $this->noble=\think\facade\Config::get("noble");
  424. $order=\think\facade\Config::get("order");
  425. $this->acton=$order['order_type'];
  426. $param = $this->request->only([
  427. 'page' => 1,
  428. 'size' => 15,
  429. 'good_name' => '',
  430. 'skucode' => '',
  431. 'plat_code' => '',
  432. 'exam_status' => '',
  433. ], 'post', 'trim');
  434. $where = [["b.is_del", "=", 0],["b.platform_id","in",$this->platformid]];
  435. if ($param['good_name'] !== "") $where[] = ['a.good_name', 'like', '%' . $param['good_name'] . '%'];
  436. if ($param['skucode'] !== '') $where [] = ['b.skucode', 'like', '%' . $param['skucode'] . '%'];
  437. if ($param['plat_code'] !== '') $where[] = ["b.plat_code", "like", '%' . $param['plat_code'] . '%'];
  438. if ($param['exam_status'] !== '') {
  439. if($param['exam_status']==1){
  440. $where[] = ['b.exam_status', "=", 6];
  441. }else{
  442. $where[] = ['b.exam_status', "<>", 6];
  443. }
  444. }
  445. if($this->request->isCx==1){
  446. $field="b.skuCode,b.platform_id platform_code,b.plat_code,b.id as platform_youzan_id,a.cat_id,a.good_name,
  447. a.good_img,a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,
  448. a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,b.exam_status,a.createrid purchase_id,
  449. a.creater purchase";
  450. }else{
  451. $field="b.skuCode,b.plat_code,b.id as platform_youzan_id,
  452. a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
  453. a.good_unit,b.addtime,b.updatetime,b.exam_status,a.spuCode,
  454. b.sale_price,b.final_price";
  455. }
  456. $count = Db::name('platform_youzan')
  457. ->alias("b")
  458. ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
  459. ->where($where)
  460. ->count();
  461. $total = ceil($count / $param['size']);
  462. $param['page'] = $param['page'] >= $total ? $total : $param['page'];
  463. $list = Db::name('platform_youzan')
  464. ->alias("b")
  465. ->field($field)
  466. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  467. ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
  468. ->where($where)
  469. ->page(intval($param['page']),intval($param['size']))
  470. ->order("b.addtime desc")
  471. ->cursor();
  472. $data = [];
  473. $yzgood = new YzGood();
  474. foreach ($list as $value) {
  475. $brand = Db::name("brand")->field('id,brand_name')->where(["id" => $value['brand_id']])->find();
  476. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  477. $unit = Db::name("unit")->field('id,unit')->where(["id" => $value['good_unit']])->find();
  478. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  479. $value['exam_status'] = $value['exam_status']==6?1:0;
  480. $value['origin_price'] =$yzgood->where(["item_no"=>$value['skuCode'],"is_del"=>0])->value("origin",'');
  481. $spec = Db::name("good_spec")->where(["spuCode" => $value['spuCode'], "is_del" => 0])->select()->toArray();
  482. $speclist = [];
  483. if (!empty($spec)) {
  484. foreach ($spec as $val) {
  485. $temp = [];
  486. $temp['spec_id'] = $val['spec_id'];
  487. $temp['spec_value_id'] = $val['spec_value_id'];
  488. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  489. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  490. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  491. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  492. $speclist[] = $temp;
  493. }
  494. }
  495. $value['good_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$value['good_img']);
  496. $value['good_info_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$value['good_img']);
  497. $value['good_thumb_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$value['good_img']);
  498. if($this->request->isCx==1){
  499. $value['cat_info'] = made($value['cat_id'], []);
  500. $platform = Db::name("platform")->field('id,platform_name')->where(["id" => $value['platform_code']])->find();
  501. $value['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
  502. $value['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
  503. $supplier = Db::name("supplier")->field('id,name')->where(["code" => $value['supplierNo']])->find();
  504. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  505. $value['company'] = isset($company['company']) ? $company['company'] : "";
  506. $value['stock_total'] = Db::name("good_stock")->where(['spuCode' => $value['spuCode'], "is_del" => 0])->sum("usable_stock");
  507. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  508. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  509. $itemid =Db::name("depart_user")->where(["uid"=>$value["purchase_id"],"is_del"=>0])->value("itemid",'');
  510. $value['company_name'] = implode('/', array_column(GetPart($itemid), 'name'));
  511. }else{
  512. unset($value['brand_id']);
  513. unset($value['good_unit']);
  514. unset($value['spuCode']);
  515. }
  516. $value['specinfo'] = $speclist;
  517. $data[] = $value;
  518. }
  519. return json_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  520. }
  521. /**
  522. * @return \think\response\Json
  523. * @throws \think\db\exception\DataNotFoundException
  524. * @throws \think\db\exception\DbException
  525. * @throws \think\db\exception\ModelNotFoundException
  526. */
  527. public function YzGoodInfo(){
  528. $param =$this->request->only(["skuCode"=>''],"post","trim");
  529. if($param['skuCode']=='') return json_show(1004,"参数 skuCode 不能为空");
  530. if($this->request->isCx==1){
  531. $field="b.skuCode,b.platform_id platform_code,b.plat_code,b.id as platform_youzan_id,a.cat_id,a.good_name,
  532. a.good_img,a.good_info_img,a.good_thumb_img,b.createrid,a.is_exclusive,a.brand_id,a.supplierNo,a.good_unit,
  533. a.noble_metal,a.companyNo,a.spuCode,a.good_type,b.creater,b.addtime,b.updatetime,b.exam_status,a.createrid purchase_id,
  534. a.creater purchase";
  535. }else{
  536. $field="b.skuCode,b.plat_code,b.id as platform_youzan_id,
  537. a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
  538. a.good_unit,b.addtime,b.updatetime,b.exam_status,a.spuCode,
  539. b.sale_price,b.final_price";
  540. }
  541. $info = Db::name('platform_youzan')
  542. ->alias("b")
  543. ->field($field)
  544. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  545. ->leftJoin("good_basic a", "a.spuCode=b.spuCode")
  546. ->where(["b.skuCode"=>$param['skuCode'],"b.is_del"=>0])->find();
  547. if($info==false) return json_show(1005,"商品数据未找到");
  548. $yzgood = new YzGood();
  549. $brand = Db::name("brand")->field('id,brand_name')->where(["id" => $info['brand_id']])->find();
  550. $info["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  551. $unit = Db::name("unit")->field('id,unit')->where(["id" => $info['good_unit']])->find();
  552. $info['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  553. $info['exam_status'] = $info['exam_status']==6?1:0;
  554. $info['origin_price'] =$yzgood->where(["item_no"=>$info['skuCode'],"is_del"=>0])->value("origin",'');
  555. $spec = Db::name("good_spec")->where(["spuCode" => $info['spuCode'], "is_del" => 0])->select()->toArray();
  556. $speclist = [];
  557. if (!empty($spec)) {
  558. foreach ($spec as $val) {
  559. $temp = [];
  560. $temp['spec_id'] = $val['spec_id'];
  561. $temp['spec_value_id'] = $val['spec_value_id'];
  562. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  563. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  564. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  565. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  566. $speclist[] = $temp;
  567. }
  568. }
  569. $info['good_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$info['good_img']);
  570. $info['good_info_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$info['good_img']);
  571. $info['good_thumb_img']=str_replace($this->origin_img_host,$this->ssl_img_host,$info['good_img']);
  572. if($this->request->isCx==1){
  573. $info['cat_info'] = made($info['cat_id'], []);
  574. $platform = Db::name("platform")->field('id,platform_name')->where(["id" => $info['platform_code']])->find();
  575. $info['platform_name'] = isset($platform['platform_name']) ? $platform['platform_name'] : "";
  576. $info['platform_code_en'] = isset($platform['platform_code_en']) ? $platform['platform_code_en'] : "";
  577. $supplier = Db::name("supplier")->field('id,name')->where(["code" => $info['supplierNo']])->find();
  578. $info['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  579. $info['company'] = isset($company['company']) ? $company['company'] : "";
  580. $info['stock_total'] = Db::name("good_stock")->where(['spuCode' => $info['spuCode'], "is_del" => 0])->sum("usable_stock");
  581. $info['exclusive'] = makeExcluse($info['is_exclusive']);
  582. $info['noble_name'] = isset($info['noble_metal']) && $info['noble_metal'] != 0 ? $this->noble[$info['noble_metal']] : "";
  583. $itemid =Db::name("depart_user")->where(["uid"=>$info["purchase_id"],"is_del"=>0])->value("itemid",'');
  584. $info['company_name'] = implode('/', array_column(GetPart($itemid), 'name'));
  585. }else{
  586. unset($info['brand_id']);
  587. unset($info['good_unit']);
  588. unset($info['spuCode']);
  589. }
  590. $info['specinfo'] = $speclist;
  591. return json_show(0,"获取成功",$info);
  592. }
  593. }