StoreCombination.php 25 KB

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