StoreCombination.php 25 KB

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