StoreLiveProduct.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * Author: 向往那片天空
  5. * Date: 2020/6/8
  6. * Time: 16:21
  7. * 微信/QQ: 250023777
  8. * 格言: 抓住中心,宁精勿杂,宁专勿多
  9. */
  10. namespace app\admin\controller\ump;
  11. use app\admin\controller\AuthController;
  12. use app\admin\model\store\StoreCategory;
  13. use app\admin\model\store\StoreDescription;
  14. use app\admin\model\store\StoreProductAttr;
  15. use app\admin\model\store\StoreProductAttrResult;
  16. use app\admin\model\store\StoreProductAttrValue;
  17. use app\admin\model\system\ShippingTemplates;
  18. use app\Request;
  19. use crmeb\services\FormBuilder as Form;
  20. use crmeb\services\JsonService;
  21. use crmeb\services\UtilService;
  22. use app\admin\model\ump\StoreActivity as StoreActivityModel;
  23. use think\facade\Route as Url;
  24. use app\admin\model\ump\StoreActivityProduct as StoreActivityProductModel;
  25. use app\admin\model\ump\StoreLiveProduct as StoreLiveProductModel;
  26. /**
  27. * 直播商品控制器
  28. * Class StoreActivityProduct
  29. * @package app\admin\controller\ump
  30. */
  31. class StoreLiveProduct extends AuthController
  32. {
  33. public function index()
  34. {
  35. $this->assign('countCombination', StoreLiveProductModel::where("is_del=0")->count());
  36. return $this->fetch();
  37. }
  38. public function save_excel()
  39. {
  40. $where = UtilService::getMore([
  41. ['is_show', ''],
  42. ['title', ''],
  43. ]);
  44. StoreLiveProductModel::SaveExcel($where);
  45. }
  46. /**
  47. * 异步获取直播数据
  48. */
  49. public function get_combination_list()
  50. {
  51. $where = UtilService::getMore([
  52. ['page', 1],
  53. ['limit', 20],
  54. ['export', 0],
  55. ['is_show', ''],
  56. ['is_host', ''],
  57. ['store_name', '']
  58. ]);
  59. $combinationList = StoreLiveProductModel::systemPage($where);
  60. if (is_object($combinationList['list'])) $combinationList['list'] = $combinationList['list']->toArray();
  61. $data = $combinationList['list']['data'];
  62. $count = StoreLiveProductModel::setWhere($where)->count();
  63. return JsonService::successlayui(['data' => $data, 'count' => $count]);
  64. }
  65. public function combination($id = 0)
  66. {
  67. if (!$id) return $this->failed('数据不存在');
  68. $product = ProductModel::get($id);
  69. if (!$product) return JsonService::fail('数据不存在!');
  70. $f = [];
  71. $f[] = Form::hidden('product_id', $id);
  72. $f[] = Form::input('title', '直播名称', $product->getData('store_name'));
  73. $f[] = Form::input('info', '直播简介', $product->getData('store_info'))->type('textarea');
  74. $f[] = Form::input('unit_name', '单位', $product->getData('unit_name'))->placeholder('个、位');
  75. $f[] = Form::select('temp_id', '砍价运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
  76. $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
  77. $menus = [];
  78. foreach ($list['data'] as $menu) {
  79. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  80. }
  81. return $menus;
  82. })->filterable(1)->col(12);
  83. $f[] = Form::dateTimeRange('section_time', '直播时间');
  84. $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
  85. $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');
  86. $f[] = Form::number('effective_time', '直播时效(单位 小时)', 24)->placeholder('请输入直播有效时间,单位:小时');
  87. $f[] = Form::number('price', '直播价')->min(0)->col(12);
  88. $f[] = Form::number('people', '直播人数')->min(2)->col(12);
  89. $f[] = Form::number('stock', '库存', $product->getData('stock'))->min(0)->precision(0)->col(12);
  90. $f[] = Form::number('sales', '销量', $product->getData('sales'))->min(0)->precision(0)->col(12);
  91. $f[] = Form::number('sort', '排序')->col(12);
  92. $f[] = Form::number('weight', '重量', 0)->min(0)->col(12);
  93. $f[] = Form::number('volume', '体积', 0)->min(0)->col(12);
  94. $f[] = Form::radio('is_host', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  95. $f[] = Form::radio('is_show', '直播状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  96. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
  97. $this->assign(compact('form'));
  98. return $this->fetch('public/form-builder');
  99. }
  100. /**
  101. * 显示创建资源表单页.
  102. *
  103. * @return \think\Response
  104. */
  105. public function create(Request $request)
  106. {
  107. $f = [];
  108. $f[] = Form::frameImageOne('product', '选择商品', Url::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px');
  109. $f[] = Form::hidden('product_id', '');
  110. $f[] = Form::input('title', '直播商品名称');
  111. // $f[] = Form::input('info', '直播简介')->type('textarea');
  112. $f[] = Form::input('unit_name', '单位')->placeholder('个、位');
  113. $f[] = Form::input('jump_url', '直播地址')->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::frameImageOne('live_logo', '直播logo', Url::buildUrl('admin/widget.images/index', array('fodder' => 'live_logo')))->icon('images')->width('100%')->height('500px');
  126. // $f[] = Form::number('effective_time', '直播时效', '24')->placeholder('请输入直播订单有效时间,单位:小时')->col(12);
  127. // $f[] = Form::number('people', '直播人数', 2)->min(2)->col(12);
  128. // $f[] = Form::number('num', '单次购买商品个数', 1)->min(1)->col(12);
  129. $f[] = Form::number('sort', '排序')->col(12);
  130. $f[] = Form::radio('is_host', '热门推荐', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  131. $form = Form::make_post_form('添加直播商品', $f, Url::buildUrl('save'));
  132. $this->assign(compact('form'));
  133. return $this->fetch('public/form-builder');
  134. }
  135. /**
  136. * 保存新建的资源
  137. * @param int $id
  138. */
  139. public function save($id = 0)
  140. {
  141. $data = UtilService::postMore([
  142. 'product_id',
  143. 'title',
  144. // 'info',
  145. ['unit_name', '个'],
  146. ['image', ''],
  147. ['images', []],
  148. // ['section_time', []],
  149. // ['effective_time', 0],
  150. ['postage', 0],
  151. ['price', 0],
  152. // ['people', 0],
  153. ['sort', 0],
  154. // ['stock', 0],
  155. // ['sales', 0],
  156. ['is_show', 0],
  157. ['is_host', 0],
  158. ['is_postage', 0],
  159. ['temp_id', ''],
  160. ['live_logo', ''],
  161. ['jump_url', ''],
  162. ['weight', ''],
  163. ['volume', ''],
  164. ['num', 1],
  165. ]);
  166. $data['description'] = StoreDescription::getDescription($data['product_id']);
  167. if (!$data['title']) return JsonService::fail('请输入直播名称');
  168. // if (!$data['info']) return JsonService::fail('请输入直播简介');
  169. if (!$data['image']) return JsonService::fail('请上传商品图片');
  170. if (!$data['live_logo']) return JsonService::fail('请上传直播logo图片');
  171. if (!$data['jump_url']) return JsonService::fail('请填写直播地址');
  172. if (count($data['images']) < 1) return JsonService::fail('请上传商品轮播图');
  173. // if ($data['effective_time'] == 0 || $data['effective_time'] < 0) return JsonService::fail('请输入直播有效时间');
  174. // if ($data['people'] == '' || $data['people'] < 1) return JsonService::fail('请输入直播人数');
  175. // if (count($data['section_time']) < 1) return JsonService::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 = StoreLiveProductModel::get($id);
  183. if (!$product) return JsonService::fail('数据不存在!');
  184. $data['product_id'] = $product['product_id'];
  185. StoreLiveProductModel::edit($data, $id);
  186. return JsonService::successful('编辑成功!');
  187. } else {
  188. $data['add_time'] = time();
  189. $res = StoreLiveProductModel::create($data);
  190. $description['product_id'] = $res['id'];
  191. $description['description'] = htmlspecialchars_decode($data['description']);
  192. $description['type'] = 5;
  193. StoreDescription::create($description);
  194. return JsonService::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 = StoreLiveProductModel::get($id);
  207. if (!$product) return JsonService::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::input('jump_url', '直播地址', $product->getData('jump_url'))->placeholder('直播地址');
  214. $f[] = Form::select('temp_id', '砍价运费模板', (string)$product->getData('temp_id'))->setOptions(function () {
  215. $list = ShippingTemplates::getList(['page' => 1, 'limit' => 20]);
  216. $menus = [];
  217. foreach ($list['data'] as $menu) {
  218. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  219. }
  220. return $menus;
  221. })->filterable(1)->col(12);
  222. // $f[] = Form::dateTimeRange('section_time', '直播时间', date("Y-m-d H:i:s", $product->getData('start_time')), date("Y-m-d H:i:s", $product->getData('stop_time')));
  223. $f[] = Form::frameImageOne('image', '商品主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $product->getData('image'))->icon('image')->width('100%')->height('500px');
  224. $f[] = Form::frameImages('images', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'images')), json_decode($product->getData('images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
  225. $f[] = Form::frameImageOne('live_logo', '直播logo', Url::buildUrl('admin/widget.images/index', array('fodder' => 'live_logo')), $product->getData('live_logo'))->icon('images')->width('100%')->height('500px');
  226. // $f[] = Form::number('effective_time', '直播时效(单位 小时)', $product->getData('effective_time'))->placeholder('请输入直播订单有效时间,单位:小时')->col(12);
  227. $f[] = Form::hidden('price', $product->getData('price'));
  228. // $f[] = Form::number('people', '直播人数', $product->getData('people'))->min(2)->col(12);
  229. // $f[] = Form::number('num', '单次购买商品个数', $product->getData('num'))->min(1)->col(12);
  230. // $f[] = Form::hidden('stock', $product->getData('stock'));
  231. // $f[] = Form::hidden('sales', $product->getData('sales'));
  232. $f[] = Form::number('sort', '排序', $product->getData('sort'))->col(12);
  233. $f[] = Form::radio('is_host', '热门推荐', $product->getData('is_host'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
  234. $f[] = Form::hidden('is_show', $product->getData('is_show'));
  235. $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save', compact('id')));
  236. $this->assign(compact('form'));
  237. return $this->fetch('public/form-builder');
  238. }
  239. /**
  240. * 删除指定资源
  241. *
  242. * @param int $id
  243. * @return \think\Response
  244. */
  245. public function delete($id)
  246. {
  247. if (!$id) return $this->failed('数据不存在');
  248. $product = StoreLiveProductModel::get($id);
  249. if (!$product) return JsonService::fail('数据不存在!');
  250. if ($product['is_del']) return JsonService::fail('已删除!');
  251. $data['is_del'] = 1;
  252. if (!StoreLiveProductModel::edit($data, $id))
  253. return JsonService::fail(StoreLiveProductModel::getErrorInfo('删除失败,请稍候再试!'));
  254. else
  255. return JsonService::successful('删除成功!');
  256. }
  257. /**
  258. * 属性页面
  259. * @param $id
  260. * @return mixed|void
  261. */
  262. public function attr($id)
  263. {
  264. if (!$id) return $this->failed('数据不存在!');
  265. $result = StoreCombinationAttrResult::getResult($id);
  266. $image = StoreLiveProductModel::where('id', $id)->value('image');
  267. $this->assign(compact('id', 'result', 'product', 'image'));
  268. return $this->fetch();
  269. }
  270. /**
  271. * 直播属性选择页面
  272. * @param $id
  273. * @return string|void
  274. * @throws \think\db\exception\DataNotFoundException
  275. * @throws \think\db\exception\DbException
  276. * @throws \think\db\exception\ModelNotFoundException
  277. */
  278. public function attr_list($id)
  279. {
  280. if (!$id) return $this->failed('数据不存在!');
  281. $combinationInfo = StoreLiveProductModel::where('id', $id)->find();
  282. $combinationResult = StoreProductAttrResult::where('product_id', $id)->where('type', 5)->value('result');
  283. $productResult = StoreProductAttrResult::where('product_id', $combinationInfo['product_id'])->where('type', 0)->value('result');
  284. if ($productResult) {
  285. $attr = json_decode($productResult, true)['attr'];
  286. // Log::write($attr,'error');
  287. $productAttr = $this->get_attr($attr, $combinationInfo['product_id'], 0);
  288. $combinationAttr = $this->get_attr($attr, $id, 5);
  289. foreach ($productAttr as $pk => $pv) {
  290. foreach ($combinationAttr as $sv) {
  291. if ($pv['detail'] == $sv['detail']) {
  292. $productAttr[$pk] = $sv;
  293. }
  294. }
  295. }
  296. } else {
  297. if ($combinationResult) {
  298. $attr = json_decode($combinationResult, true)['attr'];
  299. $productAttr = $this->get_attr($attr, $id, 5);
  300. } else {
  301. $attr[0]['value'] = '默认';
  302. $attr[0]['detailValue'] = '';
  303. $attr[0]['attrHidden'] = '';
  304. $attr[0]['detail'][0] = '默认';
  305. $productAttr[0]['value1'] = '默认';
  306. $productAttr[0]['detail'] = json_encode(['默认' => '默认']);
  307. $productAttr[0]['pic'] = $combinationInfo['image'];
  308. $productAttr[0]['price'] = $combinationInfo['price'];
  309. $productAttr[0]['cost'] = $combinationInfo['cost'];
  310. $productAttr[0]['ot_price'] = $combinationInfo['ot_price'];
  311. $productAttr[0]['stock'] = $combinationInfo['stock'];
  312. $productAttr[0]['quota'] = 0;
  313. $productAttr[0]['bar_code'] = $combinationInfo['bar_code'];
  314. $productAttr[0]['weight'] = 0;
  315. $productAttr[0]['volume'] = 0;
  316. $productAttr[0]['brokerage'] = 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 = UtilService::postMore([
  336. ['attr', []],
  337. ['ids', []],
  338. ['id', 0],
  339. ]);
  340. if (!$data['id']) return JsonService::fail('数据不存在!');
  341. if (!$data['ids']) return JsonService::fail('你没有选择任何规格!');
  342. $combinationId = StoreLiveProductModel::where('id', $data['id'])->value('product_id');
  343. //$attr = json_decode(StoreProductAttrResult::where('product_id', $combinationId)->where('type',3)->value('result'), true)['attr'];
  344. $attr = StoreProductAttrResult::where('product_id', $combinationId)->where('type', 0)->value('result');
  345. foreach ($data['attr'] as $k => $v) {
  346. if (in_array($k, $data['ids'])) {
  347. $v['detail'] = json_decode(htmlspecialchars_decode($v['detail']), true);
  348. $detail[$k] = $v;
  349. }
  350. }
  351. if (min(array_column($detail, 'quota')) == 0) return JsonService::fail('限购不能为0');
  352. $price = min(array_column($detail, 'price'));
  353. $quota = array_sum(array_column($detail, 'quota'));
  354. $stock = array_sum(array_column($detail, 'stock'));
  355. if (!$attr) {
  356. $attr[0]['value'] = '规格';
  357. $attr[0]['detailValue'] = '';
  358. $attr[0]['attrHidden'] = '';
  359. $attr[0]['detail'][0] = '默认';
  360. } else {
  361. $attr = json_decode($attr, true)['attr'];
  362. }
  363. $res = StoreProductAttr::createProductAttr($attr, $detail, $data['id'], 5);
  364. if ($res === false) {
  365. return JsonService::fail(StoreProductAttr::getErrorInfo('err'), [$attr, $detail]);
  366. }
  367. StoreLiveProductModel::where('id', $data['id'])->update(['stock' => $stock, 'quota' => $quota, 'quota_show' => $quota, 'price' => $price]);
  368. return JsonService::successful('添加成功!', [$attr, $detail]);
  369. }
  370. /**
  371. * 生成属性
  372. * @param int $id
  373. */
  374. public function is_format_attr($id = 0)
  375. {
  376. if (!$id) return JsonService::fail('商品不存在');
  377. list($attr, $detail) = UtilService::postMore([
  378. ['items', []],
  379. ['attrs', []]
  380. ], $this->request, true);
  381. $product = StoreLiveProductModel::get($id);
  382. if (!$product) return JsonService::fail('商品不存在');
  383. $attrFormat = attr_format($attr)[1];
  384. if (count($detail)) {
  385. foreach ($attrFormat as $k => $v) {
  386. foreach ($detail as $kk => $vv) {
  387. if ($v['detail'] == $vv['detail']) {
  388. $attrFormat[$k]['price'] = $vv['price'];
  389. $attrFormat[$k]['sales'] = $vv['sales'];
  390. $attrFormat[$k]['pic'] = $vv['pic'];
  391. $attrFormat[$k]['check'] = false;
  392. break;
  393. } else {
  394. $attrFormat[$k]['price'] = '';
  395. $attrFormat[$k]['sales'] = '';
  396. $attrFormat[$k]['pic'] = $product['image'];
  397. $attrFormat[$k]['check'] = true;
  398. }
  399. }
  400. }
  401. } else {
  402. foreach ($attrFormat as $k => $v) {
  403. $attrFormat[$k]['price'] = $product['price'];
  404. $attrFormat[$k]['sales'] = $product['stock'];
  405. $attrFormat[$k]['pic'] = $product['image'];
  406. $attrFormat[$k]['check'] = false;
  407. }
  408. }
  409. return JsonService::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) = UtilService::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 = StoreLiveProductModel::get($id);
  444. if (!$product) return JsonService::fail('数据不存在!');
  445. $this->assign([
  446. 'content' => htmlspecialchars_decode(StoreDescription::getDescription($id, 5)),
  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 = StoreLiveProductModel::get($id);
  456. if (!$combination) return JsonService::fail('数据不存在!');
  457. $data['description'] = request()->post('description');
  458. StoreDescription::saveDescription($data['description'], $id, 5);
  459. $res = StoreLiveProductModel::edit($data, $id);
  460. if ($res)
  461. return JsonService::successful('添加成功');
  462. else
  463. return JsonService::fail('添加失败');
  464. }
  465. /**直播列表
  466. * @return mixed
  467. */
  468. public function combina_list()
  469. {
  470. $where = UtilService::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 JsonService::fail('参数错误');
  499. $res = StoreProductAttrValue::where('product_id', $id)->where('type', 5)->find();
  500. if (!$res) return JsonService::fail('请先配置规格');
  501. $res = StoreLiveProductModel::edit(['is_show' => $status], $id);
  502. if ($res) return JsonService::successful('修改成功');
  503. else return JsonService::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', 'suk');
  533. if (count($sukValue)) {
  534. foreach (array_values($detail) as $k => $v) {
  535. $valueNew[$count]['value' . ($k + 1)] = $v;
  536. }
  537. // Log::write(json_encode($sukValue), 'error');
  538. $valueNew[$count]['detail'] = json_encode($detail);
  539. $valueNew[$count]['pic'] = $sukValue[$suk]['pic'] ?? '';
  540. $valueNew[$count]['price'] = $sukValue[$suk]['price'] ? floatval($sukValue[$suk]['price']) : 0;
  541. $valueNew[$count]['cost'] = $sukValue[$suk]['cost'] ? floatval($sukValue[$suk]['cost']) : 0;
  542. $valueNew[$count]['ot_price'] = isset($sukValue[$suk]['ot_price']) ? floatval($sukValue[$suk]['ot_price']) : 0;
  543. $valueNew[$count]['stock'] = $sukValue[$suk]['stock'] ? intval($sukValue[$suk]['stock']) : 0;
  544. $valueNew[$count]['quota'] = $sukValue[$suk]['quota'] ? intval($sukValue[$suk]['quota']) : 0;
  545. $valueNew[$count]['bar_code'] = $sukValue[$suk]['bar_code'] ?? '';
  546. $valueNew[$count]['weight'] = $sukValue[$suk]['weight'] ?? 0;
  547. $valueNew[$count]['volume'] = $sukValue[$suk]['volume'] ?? 0;
  548. $valueNew[$count]['brokerage'] = $sukValue[$suk]['brokerage'] ?? 0;
  549. $valueNew[$count]['brokerage_two'] = $sukValue[$suk]['brokerage_two'] ?? 0;
  550. $valueNew[$count]['check'] = $type != 0 ? 1 : 0;
  551. $count++;
  552. }
  553. }
  554. return $valueNew;
  555. }
  556. public function del(Request $request, $id)
  557. {
  558. //todo 判断直播下面是否有商品
  559. StoreLiveProductModel::update([
  560. 'id' => $id,
  561. 'is_del' => 1
  562. ]);
  563. return JsonService::success("删除成功");
  564. }
  565. public function set_show(Request $request)
  566. {
  567. $param = UtilService::getMore([
  568. 'id',
  569. 'is_show'
  570. ], $request);
  571. if (!$param['id']) return JsonService::fail('参数错误');
  572. $res = StoreProductAttrValue::where('product_id', $param['id'])->where('type', 5)->find();
  573. if (!$res) return JsonService::fail('请先配置规格');
  574. StoreLiveProductModel::update([
  575. 'id' => $param['id'],
  576. 'is_show' => $param['is_show']
  577. ]);
  578. JsonService::success("修改成功");
  579. }
  580. }