Goods.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?php
  2. namespace app\controller\admin\gong;
  3. use app\common\repositories\store\product\ProductRepository;
  4. use app\validate\merchant\GongProductValidate;
  5. use crmeb\basic\BaseController;
  6. use think\Exception;
  7. use think\facade\Cache;
  8. use think\facade\Db;
  9. use think\facade\Log;
  10. class Goods extends BaseController
  11. {
  12. //特殊商户ID 正式测试321
  13. private $specialMerId = 321;
  14. private $signKey = 'tdba2023!@#';
  15. // 商品类表
  16. public function lst()
  17. {
  18. [$page, $limit] = $this->getPage();
  19. $params = $this->request->params(['cate_ids','title', 'type', 'profit', 'price']);
  20. $product_model = Db::name('douhuomall')->whereIn('status', [0, 1]);
  21. $gongProduct = $this->getJoinProduct();
  22. if ($params['type'] == 1) {
  23. // 已加入商品管理
  24. $product_model->where('status', 1);
  25. } elseif ($params['type'] == 2) {
  26. // 未加入商品管理
  27. $product_model->where('status', 0);
  28. }
  29. // SQL条件拼装
  30. $product_model->whereIn('status', [0, 1])
  31. ->when(!empty($params['title']), function($query) use ($params) {
  32. $query->whereLike('title','%'.$params['title'].'%');
  33. })
  34. ->when(!empty($params['cate_ids']), function ($query) use ($params) {
  35. $query->where(function($que) use ($params) {
  36. $cateIds = explode(',', $params['cate_ids']);
  37. foreach ($cateIds as $key => $value) {
  38. $que->whereFindInSet('cate_ids', $value, 'OR');
  39. }
  40. });
  41. })
  42. ->field('spu_id,title,cost_price,market_price,profit,spuId_info,status,ot_price,mer_profit,pension');
  43. // 获取总数
  44. $count=$product_model->count('spu_id');
  45. // 按创客利润排序
  46. if (!empty($params['profit'])) {
  47. if ($params['profit'] == 'up') {
  48. $product_model->order('mer_profit', 'asc');
  49. }elseif ($params['profit'] == 'down') {
  50. $product_model->order('mer_profit', 'desc');
  51. }
  52. }
  53. // 按销售价排序
  54. if (!empty($params['price'])) {
  55. if ($params['price'] == 'up') {
  56. $product_model->order('market_price', 'asc');
  57. }elseif ($params['price'] == 'down') {
  58. $product_model->order('market_price', 'desc');
  59. }
  60. }
  61. if (empty($params['price']) && empty($params['profit'])) {
  62. $product_model->order('create_time', 'desc');
  63. }
  64. // 获取分页数据
  65. $product_lst=$product_model->page($page,$limit)->select()->toArray();
  66. foreach ($product_lst as $k=>&$v){
  67. //商品图片处理
  68. $v['spuId_info']=json_decode($v['spuId_info'],true);
  69. $v['img']=$v['spuId_info']['cover_url'];
  70. if(in_array($v['spu_id'], $gongProduct)){
  71. $v['is_join']=1;
  72. }else{
  73. $v['is_join']=0;
  74. }
  75. unset($v['spuId_info']);
  76. }
  77. $retrun_data=[
  78. 'count'=>$count,
  79. 'data'=>$product_lst
  80. ];
  81. return app('json')->success($retrun_data);
  82. }
  83. // 获取已加入选品库的商品
  84. public function getJoinProduct()
  85. {
  86. $gongProduct = Db::name('store_product')
  87. ->where('status', 1)
  88. ->whereNotNull('spu_id')
  89. ->column('spu_id');
  90. return $gongProduct;
  91. }
  92. // 获取选品库中全部、已加入3号库、未加入3号库的数量
  93. public function getStatusFilter()
  94. {
  95. // 获取全部数据
  96. $allNum = Db::name('douhuomall')->whereIn('status', [0, 1])->count();
  97. // 获取已加入3号库的数据
  98. $joinNum = Db::name('douhuomall')->where('status', 1)->count();
  99. // 获取未加入3号库的数据
  100. $notJoinNum = Db::name('douhuomall')->where('status', 0)->count();
  101. $res = [
  102. // [
  103. // 'type' => 0,
  104. // 'title' => '全部',
  105. // 'count' => $allNum
  106. // ],
  107. // [
  108. // 'type' => 1,
  109. // 'title' => '已加入3号库',
  110. // 'count' => $joinNum
  111. // ],
  112. // [
  113. // 'type' => 2,
  114. // 'title' => '未加入3号库',
  115. // 'count' => $notJoinNum
  116. // ]
  117. ];
  118. return app('json')->success($res);
  119. }
  120. //商品详情
  121. public function product_details()
  122. {
  123. $spu_id = $this->request->param('spu_id');
  124. $product_data=Db::name('douhuomall')->where('spu_id',$spu_id)->find();
  125. if (empty($product_data))
  126. return app('json')->success([]);
  127. $product_data['spuId_info']=json_decode($product_data['spuId_info'],true);
  128. $product_data['skuId_info']=json_decode($product_data['skuId_info'],true);
  129. foreach ($product_data['skuId_info'] as &$skuId){
  130. $name='';
  131. foreach($skuId['attribute_json'] as $k=>$v){
  132. $name.=$v['val'];
  133. }
  134. $skuId['attribute_json']=$name;
  135. }
  136. return app('json')->success($product_data);
  137. }
  138. // 修改价格
  139. public function update_Price()
  140. {
  141. $data = $this->request->param();
  142. $spu_id = $data['spu_id'];
  143. $res = Db::name('douhuomall')->where('spu_id', $spu_id)->update([
  144. 'update_time' => date('Y-m-d H:i:s'),
  145. 'cost_price' => $data['cost_price'],
  146. 'market_price' => $data['market_price'],
  147. 'ot_price' => $data['ot_price'],
  148. 'mer_profit' => $data['mer_profit'],
  149. 'pension' => $data['pension'],
  150. 'profit' => $data['profit'],
  151. 'title' => $data['title'],
  152. ]);
  153. if($res) {
  154. return app('json')->success('修改成功');
  155. }
  156. return app('json')->fail('修改失败');
  157. }
  158. // 上下架
  159. public function join_selection_library()
  160. {
  161. $data = $this->request->params(['spu_id']);
  162. $spu_id = $data['spu_id'];
  163. $product_data=Db::name('douhuomall')->where('spu_id',$spu_id)->find();
  164. if (empty($product_data)) return app('json')->fail('设置失败,没有找到该商品');
  165. if ($product_data['status'] == 1) {
  166. $res = Db::name('douhuomall')->where('spu_id', $spu_id)->update([
  167. 'update_time' => date('Y-m-d H:i:s'),
  168. 'status' => 0,
  169. ]);
  170. }else{
  171. $res = Db::name('douhuomall')->where('spu_id', $spu_id)->update([
  172. 'update_time' => date('Y-m-d H:i:s'),
  173. 'status' => 1,
  174. ]);
  175. }
  176. if($res) {
  177. return app('json')->success('设置成功');
  178. }
  179. return app('json')->fail('设置失败');
  180. }
  181. // 批量加入选品
  182. public function batch_join_selection_library()
  183. {
  184. $data = $this->request->params(['spu_ids']);
  185. if (empty($data['spu_ids'])) {
  186. return app('json')->fail('参数错误');
  187. }
  188. $mer_id=$this->request->merId();
  189. $joinNum = 0;
  190. $successJoin = 0;
  191. $failJoin = 0;
  192. $spuIds = explode(',', $data['spu_ids']);
  193. foreach ($spuIds as $spu_id) {
  194. $store_product_data=Db::name('store_product')->where('mer_id',$mer_id)->where('spu_id',$spu_id)->where('is_del', 0)->value('product_id');
  195. if(!empty($store_product_data)) {
  196. ++$joinNum;
  197. continue;
  198. }
  199. $res = $this->insert_product($spu_id, $mer_id);
  200. $res ? ++$successJoin : ++$failJoin;
  201. }
  202. return app('json')->success($successJoin . '个商品加入成功,' . $failJoin . '个商品加入失败,' . $joinNum . '个商品已经加入');
  203. }
  204. public function insert_product($spu_id, $mer_id) {
  205. try {
  206. $data=Db::name('douhuomall')->where('spu_id',$spu_id)->find();
  207. // 是否为多规格
  208. $sku_data=json_decode($data['skuId_info'],true);
  209. $spec_type=count($sku_data);
  210. if($spec_type>1){
  211. $spec_type=1;
  212. }else{
  213. $spec_type=0;
  214. }
  215. //商品主图
  216. $spuId_info=json_decode($data['spuId_info'],true);
  217. $slider_image=$spuId_info['detail_img_list']??'';
  218. $image=$spuId_info['cover_url']??'';
  219. $slider_image = empty($slider_image) ? $image : implode(',',json_decode($slider_image,true));
  220. $yanglaojin_scale = (!empty($data['pension']) && !empty($data['market_price'])) ? bcdiv($data['pension'], $data['market_price'], 2) : 0;
  221. //商品入库数据
  222. $product_insert_data=[
  223. 'mer_id'=>$mer_id,
  224. 'image'=>$image,
  225. 'slider_image'=>$slider_image,
  226. 'store_name'=>$data['title'],
  227. 'store_info'=>1,
  228. 'keyword'=>mb_substr($data['title'],0,3),
  229. 'is_show'=> ($mer_id == $this->specialMerId) ? 1:0,
  230. 'status'=>1,
  231. 'cate_id'=> ($mer_id == $this->specialMerId) ? $data['cxb_cate_id'] : $data['cate_ids'],
  232. 'unit_name'=>'个',
  233. 'price'=>$data['market_price'],
  234. 'cost'=>$data['cost_price'],
  235. 'ot_price'=>$data['ot_price'],
  236. 'stock'=>'1000',
  237. 'spec_type'=>$spec_type,
  238. 'extension_type'=>1,
  239. 'mer_status'=>1,
  240. 'is_used'=>1,
  241. 'old_product_id'=>$data['id'],
  242. 'volunteer'=>0,
  243. 'type'=>($mer_id == $this->specialMerId) ? 5: 1,
  244. 'pension'=>'0.00',
  245. 'commission'=>5,
  246. 'spu_id'=>$data['spu_id'],
  247. 'temp_id' => 105,
  248. 'plate_mer_profit' => $data['mer_profit'],
  249. 'concession_pri' => $data['mer_profit'],
  250. 'yanglaojin_scale' => $yanglaojin_scale
  251. ];
  252. $insert_id=Db::name('store_product')->insertGetId($product_insert_data);
  253. $detail = $spuId_info['detail'];
  254. if(!is_null(json_decode($detail))){
  255. $detail_list = json_decode($detail);
  256. $detail = '';
  257. foreach($detail_list as $value){
  258. $detail .= '<img src="'.$value.'"></img>';
  259. }
  260. }
  261. Db::name('store_product_content')->insert(['content'=>$detail,'product_id'=>$insert_id]);
  262. $this->insert_sku($insert_id,$sku_data);
  263. return true;
  264. } catch (Exception $e) {
  265. Log::error($spu_id . "加入选品失败:" . $e->getMessage());
  266. return false;
  267. }
  268. }
  269. public function insert_sku($id,$data)
  270. {
  271. $sku_attr_data=array_column($data,'attribute_json');
  272. $name='';
  273. $ProductRepository = app()->make(ProductRepository::class);
  274. if(empty($sku_attr_data[0][0])){
  275. Db::name('store_product_attr')->insert(['product_id'=>$id,'attr_name'=>'规格','attr_values'=>$name]);
  276. $key='';
  277. $num=1;
  278. foreach ($data as $k=>$v){
  279. Db::name('store_product_attr_value')->insert([
  280. 'product_id'=>$id,
  281. 'detail'=>json_encode(['规格'=>$key]),
  282. 'sku'=>$key,
  283. 'image'=>$v['img_url'],
  284. 'cost'=>$v['cost_price'],
  285. 'ot_price'=>$v['retail_price'],
  286. 'price'=>$v['market_price'],
  287. 'unique'=>$ProductRepository->setUnique($id,$v['sku_sn'],0),
  288. 'stock'=>100,
  289. 'cost_price'=>$v['cost_price'],
  290. 'extension_one'=>5,
  291. 'gong_sku_id'=>$v['sku_id'],
  292. 'gong_mer_profit' => $v['profit'],
  293. 'gong_pension' => $v['yanglaojin'],
  294. 'gong_market_price' => $v['market_price'],
  295. 'plate_mer_profit' => $v['profit']
  296. ]);
  297. $key='';
  298. $num++;
  299. }
  300. }else{
  301. foreach ($sku_attr_data as $kk=>$vv){
  302. foreach ($vv as $k1=>$v1){
  303. $name.=$v1['val'];
  304. }
  305. $name.='-!-';
  306. }
  307. $name=rtrim($name,'-!-');
  308. Db::name('store_product_attr')->insert(['product_id'=>$id,'attr_name'=>'规格','attr_values'=>$name]);
  309. $key='';
  310. $num=1;
  311. foreach ($data as $k=>$v){
  312. foreach ($v['attribute_json'] as $k2=>$v2){
  313. $key.=$v2['val'];
  314. }
  315. Db::name('store_product_attr_value')->insert([
  316. 'product_id'=>$id,
  317. 'detail'=>json_encode(['规格'=>$key]),
  318. 'sku'=>$key,
  319. 'image'=>$v['img_url'],
  320. 'cost'=>$v['cost_price'],
  321. 'ot_price'=>$v['retail_price'],
  322. 'price'=>$v['market_price'],
  323. 'unique'=>$ProductRepository->setUnique($id,$v['sku_sn'],0),
  324. 'stock'=>100,
  325. 'cost_price'=>$v['cost_price'],
  326. 'extension_one'=>5,
  327. 'gong_sku_id'=>$v['sku_id'],
  328. 'gong_mer_profit' => $v['profit'],
  329. 'gong_pension' => $v['yanglaojin'],
  330. 'gong_market_price' => $v['market_price'],
  331. 'plate_mer_profit' => $v['profit']
  332. ]);
  333. $key='';
  334. $num++;
  335. }
  336. }
  337. }
  338. public function add(GongProductValidate $validate)
  339. {
  340. $data = $this->request->params(['spu_id', 'skuId_info', 'sys_id', 'goods_id', 'spuId_info', 'sku_id', 'cate_ids', 'title', ['cxb_cate_id', 0], 'sign']);
  341. Log::channel("gong")->info("加入3号库供应链数据:" . json_encode($data));
  342. // 校验sign
  343. $checkSign = $this->checkSign($data);
  344. if (!$checkSign) {
  345. Log::channel("gong")->error('sign校验失败');
  346. return app('json')->fail('sign校验失败');
  347. }
  348. unset($data['sign']);
  349. $validate->check($data);
  350. $findData = Db::name('douhuomall')->field('id,spu_id,status')->where('spu_id', $data['spu_id'])->find();
  351. if (!empty($findData) && $findData['status'] == 1)
  352. return app('json')->success('商品已存在');
  353. try {
  354. $data['create_time'] = date('Y-m-d H:i:s');
  355. $data['status'] = 1;
  356. $data['update_time'] = date('Y-m-d H:i:s');
  357. $skuInfo = $this->arrSort(json_decode($data['skuId_info'], true), 'cost_price', SORT_ASC);
  358. $data['cost_price'] = isset($skuInfo[0]['cost_price']) ? $skuInfo[0]['cost_price'] : 0;
  359. $data['market_price'] = isset($skuInfo[0]['market_price']) ? $skuInfo[0]['market_price'] : 0;
  360. $data['ot_price'] = isset($skuInfo[0]['retail_price']) ? $skuInfo[0]['retail_price'] : 0;
  361. $data['mer_profit'] = isset($skuInfo[0]['profit']) ? $skuInfo[0]['profit'] : 0;
  362. $data['pension'] = isset($skuInfo[0]['yanglaojin']) ? $skuInfo[0]['yanglaojin'] : 0;
  363. $data['profit'] = empty($data['cost_price']) || empty($data['market_price']) ? 0 : bcdiv($data['cost_price'], $data['market_price'], 2);
  364. if (empty($findData)) {
  365. Db::name('douhuomall')->insert($data);
  366. } else {
  367. Db::name('douhuomall')->where('spu_id', $findData['spu_id'])->update([
  368. 'status' => 1,
  369. 'create_time' => date('Y-m-d H:i:s'),
  370. 'update_time' => date('Y-m-d H:i:s'),
  371. 'cost_price' => $data['cost_price'],
  372. 'market_price' => $data['market_price'],
  373. 'ot_price' => $data['ot_price'],
  374. 'mer_profit' => $data['mer_profit'],
  375. 'pension' => $data['pension'],
  376. 'profit' => $data['profit'],
  377. 'skuId_info' => $data['skuId_info'],
  378. 'spuId_info' => $data['spuId_info'],
  379. 'title' => $data['title'],
  380. 'cate_ids' => $data['cate_ids'],
  381. 'cxb_cate_id' => $data['cxb_cate_id']
  382. ]);
  383. }
  384. // 特殊商户直接加入商品库
  385. $is_exit = Db::name('store_product')
  386. ->field('product_id')
  387. ->where('spu_id', $data['spu_id'])
  388. ->where('mer_id', $this->specialMerId)
  389. ->where('is_del', 0)
  390. ->find();
  391. if (empty($is_exit)) {
  392. $this->insert_product($data['spu_id'], $this->specialMerId);
  393. }
  394. return app('json')->success('添加成功');
  395. } catch (Exception $e) {
  396. Log::channel("gong")->error("获取供应链数据失败:" . $e->getMessage());
  397. return app('json')->fail($e->getMessage());
  398. }
  399. }
  400. public function remove()
  401. {
  402. $data = $this->request->params(['token', 'sign']);
  403. Log::channel("gong")->info("供应链取消商品数据:" . json_encode($data));
  404. // 校验sign
  405. $checkSign = $this->checkSign($data);
  406. if (!$checkSign) {
  407. Log::channel("gong")->error('sign校验失败');
  408. return app('json')->fail('sign校验失败');
  409. }
  410. unset($data['sign']);
  411. if (empty($data['token'])) {
  412. return app('json')->fail('参数为空');
  413. }
  414. $spuIds = explode(',', $data['token']);
  415. Db::startTrans();
  416. try{
  417. // 删除选品库对应的数据
  418. Db::name('douhuomall')->whereIn('spu_id', $spuIds)->update([
  419. 'status' => 9,
  420. 'update_time' => date('Y-m-d H:i:s')
  421. ]);
  422. // 删除商品管理对应的数据
  423. Db::name('store_product')->whereIn('spu_id', $spuIds)->update([
  424. 'is_del' => 1,
  425. 'is_show' => 0
  426. ]);
  427. Db::commit();
  428. return app('json')->success('操作成功');
  429. } catch (Exception $e) {
  430. Db::rollback();
  431. Log::channel("gong")->error('供应链取消商品失败:' . $e->getMessage());
  432. return app('json')->fail($e->getMessage());
  433. }
  434. }
  435. public function edit()
  436. {
  437. $params = $this->request->params(['spu_id', 'sku_info', 'cxb_cate_id', 'sign']);
  438. Log::channel("gong")->info('供应链修改商品数据:' . json_encode($params));
  439. // 校验sign
  440. $checkSign = $this->checkSign($params);
  441. if (!$checkSign) {
  442. Log::channel("gong")->error('sign校验失败');
  443. return app('json')->fail('sign校验失败');
  444. }
  445. unset($params['sign']);
  446. $spu_id = $params['spu_id'];
  447. $sku_info = $params['sku_info'];
  448. $cxb_cate_id = $params['cxb_cate_id'];
  449. if (!empty($cxb_cate_id) && !empty($spu_id) && empty($sku_info)) {
  450. try{
  451. Db::startTrans();
  452. Db::name('douhuomall')->where('spu_id', $spu_id)->update([
  453. 'cxb_cate_id' => $cxb_cate_id,
  454. 'update_time' => date('Y-m-d H:i:s')
  455. ]);
  456. Db::name('store_product')->where('spu_id', $spu_id)->where('mer_id', $this->specialMerId)->update(['cate_id' => $cxb_cate_id]);
  457. Db::commit();
  458. return app('json')->success('操作成功');
  459. } catch (Exception $e) {
  460. Db::rollback();
  461. Log::channel("gong")->error('供应链修改商品分类失败:' . $e->getMessage());
  462. return app('json')->fail($e->getMessage());
  463. }
  464. }
  465. if (!empty($spu_id) && !empty($sku_info)) {
  466. try {
  467. // 修改选品库中的sku信息
  468. $data['skuId_info'] = $sku_info;
  469. $sku_info = json_decode($sku_info, true);
  470. $skuInfo = $this->arrSort($sku_info, 'cost_price', SORT_ASC);
  471. $data['cost_price'] = isset($skuInfo[0]['cost_price']) ? $skuInfo[0]['cost_price'] : 0;
  472. $data['market_price'] = isset($skuInfo[0]['market_price']) ? $skuInfo[0]['market_price'] : 0;
  473. $data['ot_price'] = isset($skuInfo[0]['retail_price']) ? $skuInfo[0]['retail_price'] : 0;
  474. $data['mer_profit'] = isset($skuInfo[0]['profit']) ? $skuInfo[0]['profit'] : 0;
  475. $data['pension'] = isset($skuInfo[0]['yanglaojin']) ? $skuInfo[0]['yanglaojin'] : 0;
  476. $data['profit'] = empty($data['cost_price']) || empty($data['market_price']) ? 0 : bcdiv($data['cost_price'], $data['market_price'], 2);
  477. $data['update_time'] = date('Y-m-d H:i:s');
  478. Db::startTrans();
  479. Db::name('douhuomall')->where('spu_id', $spu_id)->update($data);
  480. $productModel = Db::name('store_product')->where('spu_id', $spu_id)->where('is_del', 0);
  481. $productIds = $productModel->column('product_id');
  482. // 修改商品库中的sku信息
  483. foreach ($sku_info as $value) {
  484. $skuModel = Db::name('store_product_attr_value')
  485. ->where('gong_sku_id', $value['sku_sn'])
  486. ->whereIn('product_id', $productIds);
  487. $skuOld = $skuModel->select()->toArray();
  488. Log::channel("gong")->info('供应链修改之前的sku信息数据:' . json_encode($skuOld));
  489. $skuModel->update([
  490. 'price' => $value['market_price'],
  491. 'gong_mer_profit' => $value['profit'],
  492. 'gong_pension' => $value['yanglaojin'],
  493. 'gong_market_price' => $value['market_price'],
  494. 'plate_mer_profit' => $value['profit'],
  495. 'ot_price' => $value['retail_price']
  496. ]);
  497. }
  498. $productOld = $productModel->select()->toArray();
  499. Log::channel("gong")->info('供应链修改之前的商品基本信息数据:' . json_encode($productOld));
  500. $yanglaojin_scale = (!empty($data['market_price']) && !empty($data['pension'])) ? bcdiv($data['pension'], $data['market_price'], 2) : 0;
  501. $productModel->where('mer_id', '<>', $this->specialMerId)->update([
  502. 'is_show' => 0,
  503. 'price'=>$data['market_price'],
  504. 'cost'=>$data['cost_price'],
  505. 'ot_price'=>$data['ot_price'],
  506. 'plate_mer_profit' => $data['mer_profit'],
  507. 'yanglaojin_scale' => $yanglaojin_scale
  508. ]);
  509. Db::name('store_product')
  510. ->where('mer_id', $this->specialMerId)
  511. ->where('spu_id', $spu_id)
  512. ->where('is_del', 0)
  513. ->update([
  514. 'price'=>$data['market_price'],
  515. 'cost'=>$data['cost_price'],
  516. 'ot_price'=>$data['ot_price'],
  517. 'plate_mer_profit' => $data['mer_profit'],
  518. 'yanglaojin_scale' => $yanglaojin_scale
  519. ]);
  520. Db::commit();
  521. return app('json')->success('操作成功');
  522. } catch (Exception $e) {
  523. Db::rollback();
  524. Log::channel("gong")->error('供应链修改商品销售价失败:' . $e->getMessage());
  525. return app('json')->fail($e->getMessage());
  526. }
  527. }
  528. return app('json')->fail('数据错误');
  529. }
  530. public function category()
  531. {
  532. $url = "https://dc-api.hxxfb.com/douhuomallCategory/getCateAll";
  533. $result = curlGet($url);
  534. if (!isset($result['status']) || $result['status'] != 200) {
  535. return app('json')->success([]);
  536. }
  537. return app('json')->success($result);
  538. }
  539. /**
  540. * 二维数组根据某个字段排序
  541. * @param array $array 要排序的数组
  542. * @param string $keys 要排序的键字段
  543. * @param string $sort 排序类型 SORT_ASC SORT_DESC
  544. * @return array 排序后的数组
  545. */
  546. function arrSort($array, $keys, $sort = SORT_DESC) {
  547. $keysValue = [];
  548. foreach ($array as $k => $v) {
  549. $keysValue[$k] = $v[$keys];
  550. }
  551. array_multisort($keysValue, $sort, $array);
  552. return $array;
  553. }
  554. /** 校验sign
  555. * @param $data
  556. * @return false
  557. */
  558. function checkSign($data) {
  559. if (empty($data['sign'])) {
  560. return false;
  561. }
  562. $originalSign = $data['sign'];
  563. unset($data['sign']);
  564. ksort($data);
  565. $params = '';
  566. foreach($data as $key => $value) {
  567. $params .= '&' . $key . '=' . $value;
  568. }
  569. $params = ltrim($params, '&');
  570. $sign = md5($params . '&signKey=' . $this->signKey);
  571. Log::channel("gong")->info("参数sign:" .$originalSign . ',校验生成sign' . $sign);
  572. if ($originalSign != $sign) {
  573. return false;
  574. }
  575. return true;
  576. }
  577. }