StoreCombination.php 26 KB

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