Goods.php 26 KB

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