StoreCombination.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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('bingo_people', '拼中人数', 2)->min(2)->col(12);
  130. $f[] = Form::number('num', '限购个数', 1)->min(1)->col(12);
  131. $f[] = Form::number('sort', '排序')->col(12);
  132. $f[] = Form::radio('is_host', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  133. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
  134. $this->assign(compact('form'));
  135. return $this->fetch('public/form-builder');
  136. }
  137. /**
  138. * 保存新建的资源
  139. * @param int $id
  140. */
  141. public function save($id = 0)
  142. {
  143. $data = Util::postMore([
  144. 'product_id',
  145. 'title',
  146. 'info',
  147. ['unit_name', '个'],
  148. ['image', ''],
  149. ['images', []],
  150. ['section_time', []],
  151. ['effective_time', 0],
  152. ['postage', 0],
  153. ['price', 0],
  154. ['people', 0],
  155. ['bingo_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. ]);
  167. $data['description'] = StoreDescription::getDescription($data['product_id']);
  168. if (!$data['title']) return Json::fail('请输入拼团名称');
  169. if (!$data['info']) return Json::fail('请输入拼团简介');
  170. if (!$data['image']) return Json::fail('请上传商品图片');
  171. if (count($data['images']) < 1) return Json::fail('请上传商品轮播图');
  172. if ($data['effective_time'] == 0 || $data['effective_time'] < 0) return Json::fail('请输入拼团有效时间');
  173. if ($data['people'] == '' || $data['people'] < 1) return Json::fail('请输入拼团人数');
  174. if ($data['bingo_people'] == '' || $data['bingo_people'] < 1 || $data['bingo_people'] > $data['people']) 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::input('title', '拼团名称', $product->getData('title'));
  211. $f[] = Form::input('info', '拼团简介', $product->getData('info'))->type('textarea');
  212. $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
  213. $f[] = Form::select('temp_id', '砍价运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
  214. $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
  215. $menus = [];
  216. foreach ($list['data'] as $menu) {
  217. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  218. }
  219. return $menus;
  220. })->filterable(1)->col(12);
  221. $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')));
  222. $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
  223. $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');
  224. $f[] = Form::number('effective_time', '拼团时效(单位 小时)', $product->getData('effective_time'))->placeholder('请输入拼团订单有效时间,单位:小时')->col(12);
  225. $f[] = Form::hidden('price', $product->getData('price'));
  226. $f[] = Form::number('people', '拼团人数', $product->getData('people'))->min(2)->col(12);
  227. $f[] = Form::number('bingo_people', '拼中人数', $product->getData('bingo_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]['return'] = 0;
  316. // $productAttr[0]['integral'] = 0;
  317. $productAttr[0]['brokerage_two'] = 0;
  318. $productAttr[0]['check'] = 0;
  319. }
  320. }
  321. $attrs['attr'] = $attr;
  322. $attrs['value'] = $productAttr;
  323. $this->assign('attr', $attrs);
  324. $this->assign('id', $id);
  325. return $this->fetch();
  326. }
  327. /**
  328. * 拼团属性添加
  329. * @throws \think\db\exception\DataNotFoundException
  330. * @throws \think\db\exception\DbException
  331. * @throws \think\db\exception\ModelNotFoundException
  332. */
  333. public function save_attr()
  334. {
  335. $data = Util::postMore([
  336. ['attr', []],
  337. ['ids', []],
  338. ['id', 0],
  339. ]);
  340. if (!$data['id']) return Json::fail('数据不存在!');
  341. if (!$data['ids']) return Json::fail('你没有选择任何规格!');
  342. $productId = StoreCombinationModel::where('id', $data['id'])->value('product_id');
  343. $attr = json_decode(StoreProductAttrResult::where('product_id', $productId)->where('type', 0)->value('result'), true)['attr'];
  344. foreach ($data['attr'] as $k => $v) {
  345. if (in_array($k, $data['ids'])) {
  346. $v['detail'] = json_decode(htmlspecialchars_decode($v['detail']), true);
  347. $detail[$k] = $v;
  348. }
  349. }
  350. if (min(array_column($detail, 'quota')) == 0) return Json::fail('限购不能为0');
  351. $price = min(array_column($detail, 'price'));
  352. $quota = array_sum(array_column($detail, 'quota'));
  353. $stock = array_sum(array_column($detail, 'stock'));
  354. if (!$attr) {
  355. $attr[0]['value'] = '默认';
  356. $attr[0]['detailValue'] = '';
  357. $attr[0]['attrHidden'] = '';
  358. $attr[0]['detail'][0] = '默认';
  359. }
  360. StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 3);
  361. StoreCombinationModel::where('id', $data['id'])->update(['stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price]);
  362. return Json::successful('添加成功!');
  363. }
  364. /**
  365. * 生成属性
  366. * @param int $id
  367. */
  368. public function is_format_attr($id = 0)
  369. {
  370. if (!$id) return Json::fail('商品不存在');
  371. list($attr, $detail) = Util::postMore([
  372. ['items', []],
  373. ['attrs', []]
  374. ], $this->request, true);
  375. $product = StoreCombinationModel::get($id);
  376. if (!$product) return Json::fail('商品不存在');
  377. $attrFormat = attr_format($attr)[1];
  378. if (count($detail)) {
  379. foreach ($attrFormat as $k => $v) {
  380. foreach ($detail as $kk => $vv) {
  381. if ($v['detail'] == $vv['detail']) {
  382. $attrFormat[$k]['price'] = $vv['price'];
  383. // $attrFormat[$k]['return'] = $vv['return'];
  384. // $attrFormat[$k]['integral'] = $vv['integral'];
  385. $attrFormat[$k]['sales'] = $vv['sales'];
  386. $attrFormat[$k]['pic'] = $vv['pic'];
  387. $attrFormat[$k]['check'] = false;
  388. break;
  389. } else {
  390. $attrFormat[$k]['price'] = '';
  391. // $attrFormat[$k]['return'] = '';
  392. // $attrFormat[$k]['integral'] = '';
  393. $attrFormat[$k]['sales'] = '';
  394. $attrFormat[$k]['pic'] = $product['image'];
  395. $attrFormat[$k]['check'] = true;
  396. }
  397. }
  398. }
  399. } else {
  400. foreach ($attrFormat as $k => $v) {
  401. $attrFormat[$k]['price'] = $product['price'];
  402. // $attrFormat[$k]['return'] = $product['return'] ?? 0;
  403. // $attrFormat[$k]['integral'] = $product['integral'] ?? 0;
  404. $attrFormat[$k]['sales'] = $product['stock'];
  405. $attrFormat[$k]['pic'] = $product['image'];
  406. $attrFormat[$k]['check'] = false;
  407. }
  408. }
  409. return Json::successful($attrFormat);
  410. }
  411. /**
  412. * 添加 修改属性
  413. * @param $id
  414. */
  415. public function set_attr($id)
  416. {
  417. if (!$id) return $this->failed('商品不存在!');
  418. list($attr, $detail) = Util::postMore([
  419. ['items', []],
  420. ['attrs', []]
  421. ], $this->request, true);
  422. $res = StoreCombinationAttr::createProductAttr($attr, $detail, $id);
  423. if ($res)
  424. return $this->successful('编辑属性成功!');
  425. else
  426. return $this->failed(StoreCombinationAttr::getErrorInfo());
  427. }
  428. /**
  429. * 清除属性
  430. * @param $id
  431. */
  432. public function clear_attr($id)
  433. {
  434. if (!$id) return $this->failed('商品不存在!');
  435. if (false !== StoreCombinationAttr::clearProductAttr($id) && false !== StoreCombinationAttrResult::clearResult($id))
  436. return $this->successful('清空商品属性成功!');
  437. else
  438. return $this->failed(StoreCombinationAttr::getErrorInfo('清空商品属性失败!'));
  439. }
  440. public function edit_content($id)
  441. {
  442. if (!$id) return $this->failed('数据不存在');
  443. $product = StoreCombinationModel::get($id);
  444. if (!$product) return Json::fail('数据不存在!');
  445. $this->assign([
  446. 'content' => htmlspecialchars_decode(StoreDescription::getDescription($id, 3)),
  447. 'field' => 'description',
  448. 'action' => Url::buildUrl('change_field', ['id' => $id, 'field' => 'description'])
  449. ]);
  450. return $this->fetch('public/edit_content');
  451. }
  452. public function change_field($id)
  453. {
  454. if (!$id) return $this->failed('数据不存在');
  455. $combination = StoreCombinationModel::get($id);
  456. if (!$combination) return Json::fail('数据不存在!');
  457. $data['description'] = request()->post('description');
  458. StoreDescription::saveDescription($data['description'], $id, 3);
  459. $res = StoreCombinationModel::edit($data, $id);
  460. if ($res)
  461. return Json::successful('添加成功');
  462. else
  463. return Json::fail('添加失败');
  464. }
  465. /**拼团列表
  466. * @return mixed
  467. */
  468. public function combina_list()
  469. {
  470. $where = Util::getMore([
  471. ['status', ''],
  472. ['data', ''],
  473. ], $this->request);
  474. $this->assign('where', $where);
  475. $this->assign(StorePink::systemPage($where));
  476. return $this->fetch();
  477. }
  478. /**拼团人列表
  479. * @return mixed
  480. */
  481. public function order_pink($id)
  482. {
  483. if (!$id) return $this->failed('数据不存在');
  484. $StorePink = StorePink::getPinkUserOne($id);
  485. if (!$StorePink) return $this->failed('数据不存在!');
  486. $list = StorePink::getPinkMember($id);
  487. $list[] = $StorePink;
  488. $this->assign('list', $list);
  489. return $this->fetch();
  490. }
  491. /**
  492. * 修改拼团状态
  493. * @param $status
  494. * @param int $idd
  495. */
  496. public function set_combination_status($status, $id = 0)
  497. {
  498. if (!$id) return Json::fail('参数错误');
  499. $res = StoreProductAttrValue::where('product_id', $id)->where('type', 3)->find();
  500. if (!$res) return Json::fail('请先配置规格');
  501. $res = StoreCombinationModel::edit(['is_show' => $status], $id);
  502. if ($res) return Json::successful('修改成功');
  503. else return Json::fail('修改失败');
  504. }
  505. /**
  506. * 添加拼团获取商品列表
  507. * @return string
  508. * @throws \Exception
  509. */
  510. public function productList()
  511. {
  512. $cate = StoreCategory::getTierList(null, 1);
  513. $this->assign('cate', $cate);
  514. return $this->fetch();
  515. }
  516. /**
  517. * 获取拼团商品规格
  518. * @param $attr
  519. * @param $id
  520. * @param $type
  521. * @return array
  522. */
  523. public function get_attr($attr, $id, $type)
  524. {
  525. $value = attr_format($attr)[1];
  526. $valueNew = [];
  527. $count = 0;
  528. foreach ($value as $key => $item) {
  529. $detail = $item['detail'];
  530. // sort($item['detail'], SORT_STRING);
  531. $suk = implode(',', $item['detail']);
  532. $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,return,integral', 'suk');
  533. if (count($sukValue)) {
  534. foreach (array_values($detail) as $k => $v) {
  535. $valueNew[$count]['value' . ($k + 1)] = $v;
  536. }
  537. $valueNew[$count]['detail'] = json_encode($detail);
  538. $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
  539. $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
  540. // $valueNew[$count]['return'] = $sukValue[$suk]['return'] ? floatval($sukValue[$suk]['return']) : 0;
  541. // $valueNew[$count]['integral'] = $sukValue[$suk]['integral'] ? floatval($sukValue[$suk]['integral']) : 0;
  542. $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;
  543. $valueNew[$count]['ot_price'] = isset($sukValue[$suk]['ot_price']) ? floatval($sukValue[$suk]['ot_price']) : 0;
  544. $valueNew[$count]['stock'] = $sukValue[$suk]['stock'] ? intval($sukValue[$suk]['stock']) : 0;
  545. $valueNew[$count]['quota'] = $sukValue[$suk]['quota'] ? intval($sukValue[$suk]['quota']) : 0;
  546. $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
  547. $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
  548. $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
  549. $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
  550. $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
  551. $valueNew[$count]['check'] = $type != 0 ? 1 : 0;
  552. $count++;
  553. }
  554. }
  555. return $valueNew;
  556. }
  557. }