StoreCombination.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <?php
  2. namespace app\admin\controller\ump;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\store\{StoreCategory,
  5. StoreDescription,
  6. StoreProductAttr,
  7. StoreProductAttrResult,
  8. StoreProduct as ProductModel,
  9. StoreProductAttrValue
  10. };
  11. use crmeb\traits\CurdControllerTrait;
  12. use app\admin\model\ump\{StorePink,
  13. StoreCombinationAttr,
  14. StoreCombinationAttrResult,
  15. StoreCombination as StoreCombinationModel
  16. };
  17. use think\facade\Route as Url;
  18. use app\admin\model\system\{SystemAttachment, ShippingTemplates};
  19. use crmeb\services\{FormBuilder as Form, UtilService as Util, JsonService as Json};
  20. /**
  21. * 拼团管理
  22. * Class StoreCombination
  23. * @package app\admin\controller\store
  24. */
  25. class StoreCombination extends AuthController
  26. {
  27. use CurdControllerTrait;
  28. protected $bindModel = StoreCombinationModel::class;
  29. /**
  30. * @return mixed
  31. */
  32. public function index()
  33. {
  34. $this->assign('countCombination', StoreCombinationModel::getCombinationCount());
  35. $this->assign(StoreCombinationModel::getStatistics());
  36. $this->assign('combinationId', StoreCombinationModel::getCombinationIdAll());
  37. return $this->fetch();
  38. }
  39. public function save_excel()
  40. {
  41. $where = Util::getMore([
  42. ['is_show', ''],
  43. ['store_name', ''],
  44. ]);
  45. StoreCombinationModel::SaveExcel($where);
  46. }
  47. /**
  48. * 异步获取拼团数据
  49. */
  50. public function get_combination_list()
  51. {
  52. $where = Util::getMore([
  53. ['page', 1],
  54. ['limit', 20],
  55. ['export', 0],
  56. ['is_show', ''],
  57. ['is_host', ''],
  58. ['store_name', '']
  59. ]);
  60. $combinationList = StoreCombinationModel::systemPage($where);
  61. if (is_object($combinationList['list'])) $combinationList['list'] = $combinationList['list']->toArray();
  62. $data = $combinationList['list']['data'];
  63. foreach ($data as $k => $v) {
  64. $data[$k]['_stop_time'] = date('Y/m/d H:i:s', $v['stop_time']);
  65. }
  66. return Json::successlayui(['count' => $combinationList['list']['total'], 'data' => $data]);
  67. }
  68. public function combination($id = 0)
  69. {
  70. if (!$id) return $this->failed('数据不存在');
  71. $product = ProductModel::get($id);
  72. if (!$product) return Json::fail('数据不存在!');
  73. $f = [];
  74. $f[] = Form::hidden('product_id', $id);
  75. $f[] = Form::hidden('store_id', $product->getData('store_id'));
  76. $f[] = Form::input('title', '拼团名称', $product->getData('store_name'));
  77. $f[] = Form::input('info', '拼团简介', $product->getData('store_info'))->type('textarea');
  78. $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
  79. $f[] = Form::select('temp_id', '砍价运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
  80. $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
  81. $menus = [];
  82. foreach ($list['data'] as $menu) {
  83. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  84. }
  85. return $menus;
  86. })->filterable(1)->col(12);
  87. $f[] = Form::dateTimeRange('section_time', '拼团时间');
  88. $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
  89. $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')), json_decode($product->getData('slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px');
  90. $f[] = Form::number('effective_time', '拼团时效(单位 小时)', 24)->placeholder('请输入拼团有效时间,单位:小时');
  91. $f[] = Form::number('price', '拼团价')->min(0)->col(12);
  92. $f[] = Form::number('people', '拼团人数')->min(2)->col(12);
  93. $f[] = Form::number('stock', '库存', $product->getData('stock'))->min(0)->precision(0)->col(12);
  94. $f[] = Form::number('sales', '销量', $product->getData('sales'))->min(0)->precision(0)->col(12);
  95. $f[] = Form::number('sort', '排序')->col(12);
  96. $f[] = Form::number('weight', '重量', 0)->min(0)->col(12);
  97. $f[] = Form::number('volume', '体积', 0)->min(0)->col(12);
  98. $f[] = Form::radio('is_host', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  99. $f[] = Form::radio('is_show', '活动状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  100. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
  101. $this->assign(compact('form'));
  102. return $this->fetch('public/form-builder');
  103. }
  104. /**
  105. * 显示创建资源表单页.
  106. *
  107. * @return \think\Response
  108. */
  109. public function create()
  110. {
  111. $f = [];
  112. $f[] = Form::frameImageOne('product', '选择商品', Url::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px');
  113. $f[] = Form::hidden('product_id', '');
  114. $f[] = Form::hidden('store_id', '');
  115. $f[] = Form::input('title', '拼团名称');
  116. $f[] = Form::input('info', '拼团简介')->type('textarea');
  117. $f[] = Form::input('unit_name', '单位')->placeholder('个、位');
  118. $f[] = Form::select('temp_id', '秒杀运费模板')->setOptions(function () {
  119. $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
  120. $menus = [];
  121. foreach ($list['data'] as $menu) {
  122. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  123. }
  124. return $menus;
  125. })->filterable(1)->col(12);
  126. $f[] = Form::dateTimeRange('section_time', '拼团时间');
  127. $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  128. $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
  129. $f[] = Form::number('effective_time', '拼团时效', '24')->placeholder('请输入拼团订单有效时间,单位:小时')->col(12);
  130. $f[] = Form::number('people', '拼团人数', 2)->min(2)->col(12);
  131. $f[] = Form::number('num', '单次购买商品个数', 1)->min(1)->col(12);
  132. $f[] = Form::number('sort', '排序')->col(12);
  133. $f[] = Form::radio('is_host', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  134. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
  135. $this->assign(compact('form'));
  136. return $this->fetch('public/form-builder');
  137. }
  138. /**
  139. * 保存新建的资源
  140. * @param int $id
  141. */
  142. public function save($id = 0)
  143. {
  144. $data = Util::postMore([
  145. 'product_id',
  146. 'title',
  147. 'info',
  148. ['unit_name', '个'],
  149. ['image', ''],
  150. ['images', []],
  151. ['section_time', []],
  152. ['effective_time', 0],
  153. ['postage', 0],
  154. ['price', 0],
  155. ['people', 0],
  156. ['sort', 0],
  157. ['stock', 0],
  158. ['sales', 0],
  159. ['is_show', 0],
  160. ['is_host', 0],
  161. ['is_postage', 0],
  162. ['temp_id', ''],
  163. ['weight', ''],
  164. ['volume', ''],
  165. ['num', 1],
  166. ['store_id', 0],
  167. ]);
  168. $data['description'] = StoreDescription::getDescription($data['product_id']);
  169. if (!$data['title']) return Json::fail('请输入拼团名称');
  170. if (!$data['info']) return Json::fail('请输入拼团简介');
  171. if (!$data['image']) return Json::fail('请上传商品图片');
  172. if (count($data['images']) < 1) return Json::fail('请上传商品轮播图');
  173. if ($data['effective_time'] == 0 || $data['effective_time'] < 0) return Json::fail('请输入拼团有效时间');
  174. if ($data['people'] == '' || $data['people'] < 1) return Json::fail('请输入拼团人数');
  175. if (count($data['section_time']) < 1) return Json::fail('请选择活动时间');
  176. $data['images'] = json_encode($data['images']);
  177. $data['start_time'] = strtotime($data['section_time'][0]);
  178. $data['stop_time'] = strtotime($data['section_time'][1]);
  179. unset($data['section_time']);
  180. if ($id) {
  181. unset($data['description']);
  182. $product = StoreCombinationModel::get($id);
  183. if (!$product) return Json::fail('数据不存在!');
  184. $data['product_id'] = $product['product_id'];
  185. StoreCombinationModel::edit($data, $id);
  186. return Json::successful('编辑成功!');
  187. } else {
  188. $data['add_time'] = time();
  189. $res = StoreCombinationModel::create($data);
  190. $description['product_id'] = $res['id'];
  191. $description['description'] = htmlspecialchars_decode($data['description']);
  192. $description['type'] = 3;
  193. StoreDescription::create($description);
  194. return Json::successful('添加拼团成功!');
  195. }
  196. }
  197. /**
  198. * 显示编辑资源表单页.
  199. *
  200. * @param int $id
  201. * @return \think\Response
  202. */
  203. public function edit($id)
  204. {
  205. if (!$id) return $this->failed('数据不存在');
  206. $product = StoreCombinationModel::get($id);
  207. if (!$product) return Json::fail('数据不存在!');
  208. $f = [];
  209. $f[] = Form::input('product_id', '产品ID', $product->getData('product_id'))->disabled(true);
  210. $f[] = Form::hidden('store_id', $product->getData('store_id'));
  211. $f[] = Form::input('title', '拼团名称', $product->getData('title'));
  212. $f[] = Form::input('info', '拼团简介', $product->getData('info'))->type('textarea');
  213. $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
  214. $f[] = Form::select('temp_id', '砍价运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
  215. $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
  216. $menus = [];
  217. foreach ($list['data'] as $menu) {
  218. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  219. }
  220. return $menus;
  221. })->filterable(1)->col(12);
  222. $f[] = Form::dateTimeRange('section_time', '拼团时间', date("Y-m-d H:i:s", $product->getData('start_time')), date("Y-m-d H:i:s", $product->getData('stop_time')));
  223. $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
  224. $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')), json_decode($product->getData('images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
  225. $f[] = Form::number('effective_time', '拼团时效(单位 小时)', $product->getData('effective_time'))->placeholder('请输入拼团订单有效时间,单位:小时')->col(12);
  226. $f[] = Form::hidden('price', $product->getData('price'));
  227. $f[] = Form::number('people', '拼团人数', $product->getData('people'))->min(2)->col(12);
  228. $f[] = Form::number('num', '单次购买商品个数', $product->getData('num'))->min(1)->col(12);
  229. $f[] = Form::hidden('stock', $product->getData('stock'));
  230. $f[] = Form::hidden('sales', $product->getData('sales'));
  231. $f[] = Form::number('sort', '排序', $product->getData('sort'))->col(12);
  232. $f[] = Form::radio('is_host', '热门推荐', $product->getData('is_host'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  233. $f[] = Form::hidden('is_show', $product->getData('is_show'));
  234. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save', compact('id')));
  235. $this->assign(compact('form'));
  236. return $this->fetch('public/form-builder');
  237. }
  238. /**
  239. * 删除指定资源
  240. *
  241. * @param int $id
  242. * @return \think\Response
  243. */
  244. public function delete($id)
  245. {
  246. if (!$id) return $this->failed('数据不存在');
  247. $product = StoreCombinationModel::get($id);
  248. if (!$product) return Json::fail('数据不存在!');
  249. if ($product['is_del']) return Json::fail('已删除!');
  250. $data['is_del'] = 1;
  251. if (!StoreCombinationModel::edit($data, $id))
  252. return Json::fail(StoreCombinationModel::getErrorInfo('删除失败,请稍候再试!'));
  253. else
  254. return Json::successful('删除成功!');
  255. }
  256. /**
  257. * 属性页面
  258. * @param $id
  259. * @return mixed|void
  260. */
  261. public function attr($id)
  262. {
  263. if (!$id) return $this->failed('数据不存在!');
  264. $result = StoreCombinationAttrResult::getResult($id);
  265. $image = StoreCombinationModel::where('id', $id)->value('image');
  266. $this->assign(compact('id', 'result', 'product', 'image'));
  267. return $this->fetch();
  268. }
  269. /**
  270. * 拼团属性选择页面
  271. * @param $id
  272. * @return string|void
  273. * @throws \think\db\exception\DataNotFoundException
  274. * @throws \think\db\exception\DbException
  275. * @throws \think\db\exception\ModelNotFoundException
  276. */
  277. public function attr_list($id)
  278. {
  279. if (!$id) return $this->failed('数据不存在!');
  280. $combinationInfo = StoreCombinationModel::where('id', $id)->find();
  281. $combinationResult = StoreProductAttrResult::where('product_id', $id)->where('type', 3)->value('result');
  282. $productResult = StoreProductAttrResult::where('product_id', $combinationInfo['product_id'])->where('type', 0)->value('result');
  283. if ($productResult) {
  284. $attr = json_decode($productResult, true)['attr'];
  285. $productAttr = $this->get_attr($attr, $combinationInfo['product_id'], 0);
  286. $combinationAttr = $this->get_attr($attr, $id, 3);
  287. foreach ($productAttr as $pk => $pv) {
  288. foreach ($combinationAttr as $sv) {
  289. if ($pv['detail'] == $sv['detail']) {
  290. $productAttr[$pk] = $sv;
  291. }
  292. }
  293. }
  294. } else {
  295. if ($combinationResult) {
  296. $attr = json_decode($combinationResult, true)['attr'];
  297. $productAttr = $this->get_attr($attr, $id, 3);
  298. } else {
  299. $attr[0]['value'] = '默认';
  300. $attr[0]['detailValue'] = '';
  301. $attr[0]['attrHidden'] = '';
  302. $attr[0]['detail'][0] = '默认';
  303. $productAttr[0]['value1'] = '默认';
  304. $productAttr[0]['detail'] = json_encode(['默认' => '默认']);
  305. $productAttr[0]['pic'] = $combinationInfo['image'];
  306. $productAttr[0]['price'] = $combinationInfo['price'];
  307. $productAttr[0]['cost'] = $combinationInfo['cost'];
  308. $productAttr[0]['ot_price'] = $combinationInfo['ot_price'];
  309. $productAttr[0]['stock'] = $combinationInfo['stock'];
  310. $productAttr[0]['quota'] = 0;
  311. $productAttr[0]['bar_code'] = $combinationInfo['bar_code'];
  312. $productAttr[0]['weight'] = 0;
  313. $productAttr[0]['volume'] = 0;
  314. $productAttr[0]['brokerage'] = 0;
  315. $productAttr[0]['brokerage_two'] = 0;
  316. $productAttr[0]['check'] = 0;
  317. }
  318. }
  319. $attrs['attr'] = $attr;
  320. $attrs['value'] = $productAttr;
  321. $this->assign('attr', $attrs);
  322. $this->assign('id', $id);
  323. return $this->fetch();
  324. }
  325. /**
  326. * 拼团属性添加
  327. * @throws \think\db\exception\DataNotFoundException
  328. * @throws \think\db\exception\DbException
  329. * @throws \think\db\exception\ModelNotFoundException
  330. */
  331. public function save_attr()
  332. {
  333. $data = Util::postMore([
  334. ['attr', []],
  335. ['ids', []],
  336. ['id', 0],
  337. ]);
  338. if (!$data['id']) return Json::fail('数据不存在!');
  339. if (!$data['ids']) return Json::fail('你没有选择任何规格!');
  340. $productId = StoreCombinationModel::where('id', $data['id'])->value('product_id');
  341. $attr = json_decode(StoreProductAttrResult::where('product_id', $productId)->where('type', 0)->value('result'), true)['attr'];
  342. foreach ($data['attr'] as $k => $v) {
  343. if (in_array($k, $data['ids'])) {
  344. $v['detail'] = json_decode(htmlspecialchars_decode($v['detail']), true);
  345. $detail[$k] = $v;
  346. }
  347. }
  348. if (min(array_column($detail, 'quota')) == 0) return Json::fail('限购不能为0');
  349. $price = min(array_column($detail, 'price'));
  350. $quota = array_sum(array_column($detail, 'quota'));
  351. $stock = array_sum(array_column($detail, 'stock'));
  352. if (!$attr) {
  353. $attr[0]['value'] = '默认';
  354. $attr[0]['detailValue'] = '';
  355. $attr[0]['attrHidden'] = '';
  356. $attr[0]['detail'][0] = '默认';
  357. }
  358. StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 3);
  359. StoreCombinationModel::where('id', $data['id'])->update(['stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price]);
  360. return Json::successful('添加成功!');
  361. }
  362. /**
  363. * 生成属性
  364. * @param int $id
  365. */
  366. public function is_format_attr($id = 0)
  367. {
  368. if (!$id) return Json::fail('商品不存在');
  369. list($attr, $detail) = Util::postMore([
  370. ['items', []],
  371. ['attrs', []]
  372. ], $this->request, true);
  373. $product = StoreCombinationModel::get($id);
  374. if (!$product) return Json::fail('商品不存在');
  375. $attrFormat = attr_format($attr)[1];
  376. if (count($detail)) {
  377. foreach ($attrFormat as $k => $v) {
  378. foreach ($detail as $kk => $vv) {
  379. if ($v['detail'] == $vv['detail']) {
  380. $attrFormat[$k]['price'] = $vv['price'];
  381. $attrFormat[$k]['sales'] = $vv['sales'];
  382. $attrFormat[$k]['pic'] = $vv['pic'];
  383. $attrFormat[$k]['check'] = false;
  384. break;
  385. } else {
  386. $attrFormat[$k]['price'] = '';
  387. $attrFormat[$k]['sales'] = '';
  388. $attrFormat[$k]['pic'] = $product['image'];
  389. $attrFormat[$k]['check'] = true;
  390. }
  391. }
  392. }
  393. } else {
  394. foreach ($attrFormat as $k => $v) {
  395. $attrFormat[$k]['price'] = $product['price'];
  396. $attrFormat[$k]['sales'] = $product['stock'];
  397. $attrFormat[$k]['pic'] = $product['image'];
  398. $attrFormat[$k]['check'] = false;
  399. }
  400. }
  401. return Json::successful($attrFormat);
  402. }
  403. /**
  404. * 添加 修改属性
  405. * @param $id
  406. */
  407. public function set_attr($id)
  408. {
  409. if (!$id) return $this->failed('商品不存在!');
  410. list($attr, $detail) = Util::postMore([
  411. ['items', []],
  412. ['attrs', []]
  413. ], $this->request, true);
  414. $res = StoreCombinationAttr::createProductAttr($attr, $detail, $id);
  415. if ($res)
  416. return $this->successful('编辑属性成功!');
  417. else
  418. return $this->failed(StoreCombinationAttr::getErrorInfo());
  419. }
  420. /**
  421. * 清除属性
  422. * @param $id
  423. */
  424. public function clear_attr($id)
  425. {
  426. if (!$id) return $this->failed('商品不存在!');
  427. if (false !== StoreCombinationAttr::clearProductAttr($id) && false !== StoreCombinationAttrResult::clearResult($id))
  428. return $this->successful('清空商品属性成功!');
  429. else
  430. return $this->failed(StoreCombinationAttr::getErrorInfo('清空商品属性失败!'));
  431. }
  432. public function edit_content($id)
  433. {
  434. if (!$id) return $this->failed('数据不存在');
  435. $product = StoreCombinationModel::get($id);
  436. if (!$product) return Json::fail('数据不存在!');
  437. $this->assign([
  438. 'content' => htmlspecialchars_decode(StoreDescription::getDescription($id, 3)),
  439. 'field' => 'description',
  440. 'action' => Url::buildUrl('change_field', ['id' => $id, 'field' => 'description'])
  441. ]);
  442. return $this->fetch('public/edit_content');
  443. }
  444. public function change_field($id)
  445. {
  446. if (!$id) return $this->failed('数据不存在');
  447. $combination = StoreCombinationModel::get($id);
  448. if (!$combination) return Json::fail('数据不存在!');
  449. $data['description'] = request()->post('description');
  450. StoreDescription::saveDescription($data['description'], $id, 3);
  451. $res = StoreCombinationModel::edit($data, $id);
  452. if ($res)
  453. return Json::successful('添加成功');
  454. else
  455. return Json::fail('添加失败');
  456. }
  457. /**拼团列表
  458. * @return mixed
  459. */
  460. public function combina_list()
  461. {
  462. $where = Util::getMore([
  463. ['status', ''],
  464. ['data', ''],
  465. ], $this->request);
  466. $this->assign('where', $where);
  467. $this->assign(StorePink::systemPage($where));
  468. return $this->fetch();
  469. }
  470. /**拼团人列表
  471. * @return mixed
  472. */
  473. public function order_pink($id)
  474. {
  475. if (!$id) return $this->failed('数据不存在');
  476. $StorePink = StorePink::getPinkUserOne($id);
  477. if (!$StorePink) return $this->failed('数据不存在!');
  478. $list = StorePink::getPinkMember($id);
  479. $list[] = $StorePink;
  480. $this->assign('list', $list);
  481. return $this->fetch();
  482. }
  483. /**
  484. * 修改拼团状态
  485. * @param $status
  486. * @param int $idd
  487. */
  488. public function set_combination_status($status, $id = 0)
  489. {
  490. if (!$id) return Json::fail('参数错误');
  491. $res = StoreProductAttrValue::where('product_id', $id)->where('type', 3)->find();
  492. if (!$res) return Json::fail('请先配置规格');
  493. $res = StoreCombinationModel::edit(['is_show' => $status], $id);
  494. if ($res) return Json::successful('修改成功');
  495. else return Json::fail('修改失败');
  496. }
  497. /**
  498. * 添加拼团获取商品列表
  499. * @return string
  500. * @throws \Exception
  501. */
  502. public function productList()
  503. {
  504. $cate = StoreCategory::getTierList(null, 1);
  505. $this->assign('cate', $cate);
  506. return $this->fetch();
  507. }
  508. /**
  509. * 获取拼团商品规格
  510. * @param $attr
  511. * @param $id
  512. * @param $type
  513. * @return array
  514. */
  515. public function get_attr($attr, $id, $type)
  516. {
  517. $value = attr_format($attr)[1];
  518. $valueNew = [];
  519. $count = 0;
  520. foreach ($value as $key => $item) {
  521. $detail = $item['detail'];
  522. // sort($item['detail'], SORT_STRING);
  523. $suk = implode(',', $item['detail']);
  524. $sukValue = StoreProductAttrValue::where('product_id', $id)->where('type', $type)->where('suk', $suk)->column('bar_code,cost,price,ot_price,stock,image as pic,weight,volume,brokerage,brokerage_two,quota', 'suk');
  525. if (count($sukValue)) {
  526. foreach (array_values($detail) as $k => $v) {
  527. $valueNew[$count]['value' . ($k + 1)] = $v;
  528. }
  529. $valueNew[$count]['detail'] = json_encode($detail);
  530. $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
  531. $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
  532. $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;
  533. $valueNew[$count]['ot_price'] = isset($sukValue[$suk]['ot_price']) ? floatval($sukValue[$suk]['ot_price']) : 0;
  534. $valueNew[$count]['stock'] = $sukValue[$suk]['stock'] ? intval($sukValue[$suk]['stock']) : 0;
  535. $valueNew[$count]['quota'] = $sukValue[$suk]['quota'] ? intval($sukValue[$suk]['quota']) : 0;
  536. $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
  537. $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
  538. $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
  539. $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
  540. $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
  541. $valueNew[$count]['check'] = $type != 0 ? 1 : 0;
  542. $count++;
  543. }
  544. }
  545. return $valueNew;
  546. }
  547. }