Good.php 27 KB

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