DiyPro.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\diy;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\diy\DiyProServices;
  14. use app\services\product\product\StoreProductServices;
  15. use think\facade\App;
  16. class DiyPro extends AuthController
  17. {
  18. public function __construct(App $app, DiyProServices $services)
  19. {
  20. parent::__construct($app);
  21. $this->services = $services;
  22. }
  23. public function getList()
  24. {
  25. return app('json')->success($this->services->getList());
  26. }
  27. public function getInfo($id = 0)
  28. {
  29. if ($id == 0) return app('json')->fail('参数错误');
  30. return app('json')->success($this->services->getInfo($id));
  31. }
  32. public function saveInfo($id = 0)
  33. {
  34. $data = $this->request->postMore([
  35. ['name', ''],
  36. ['title', ''],
  37. ['value', ''],
  38. ['type', 1],
  39. ['cover_image', ''],
  40. ['is_show', 0],
  41. ['is_bg_color', 0],
  42. ['is_bg_pic', 0],
  43. ['bg_tab_val', 0],
  44. ['color_picker', ''],
  45. ['bg_pic', ''],
  46. ['is_diy', 1],
  47. ['is_pro', 1],
  48. ['type', 2],
  49. ]);
  50. $value = is_string($data['value']) ? json_decode($data['value'], true) : $data['value'];
  51. foreach ($value as &$item) {
  52. if ($item['name'] === 'goodList') {
  53. if (isset($item['selectConfig']['list'])) {
  54. unset($item['selectConfig']['list']);
  55. }
  56. if (isset($item['goodsList']['list']) && is_array($item['goodsList']['list'])) {
  57. $limitMax = config('database.page.limitMax', 50);
  58. if (isset($item['numConfig']['val']) && isset($item['tabConfig']['tabVal']) && $item['tabConfig']['tabVal'] == 0 && $item['numConfig']['val'] > $limitMax) {
  59. return app('json')->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
  60. }
  61. $item['goodsList']['ids'] = array_column($item['goodsList']['list'], 'id');
  62. unset($item['goodsList']['list'], $item['productList']['list']);
  63. }
  64. } elseif ($item['name'] === 'articleList') {
  65. if (isset($item['selectList']['list']) && is_array($item['selectList']['list'])) {
  66. unset($item['selectList']['list']);
  67. }
  68. } elseif ($item['name'] === 'promotionList') {
  69. if (isset($item['tabConfig']['list']) && $item['tabConfig']['list']) {
  70. $list = $item['tabConfig']['list'];
  71. foreach ($list as &$tabValue) {
  72. if (isset($tabValue['goodsList']['list']) && is_array($tabValue['goodsList']['list'])) {
  73. $limitMax = config('database.page.limitMax', 50);
  74. if (isset($tabValue['numConfig']['val']) && isset($tabValue['tabConfig']['tabVal']) && $tabValue['tabConfig']['tabVal'] == 0 && $tabValue['numConfig']['val'] > $limitMax) {
  75. return app('json')->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
  76. }
  77. $tabValue['goodsList']['ids'] = array_column($tabValue['goodsList']['list'], 'id');
  78. }
  79. unset($tabValue['goodsList']['list'], $tabValue['productList']['list']);
  80. }
  81. $item['tabConfig']['list'] = $list;
  82. }
  83. } elseif ($item['name'] === 'newVip') {
  84. unset($item['newVipList']['list']);
  85. } elseif ($item['name'] === 'shortVideo') {
  86. unset($item['videoList']);
  87. }
  88. }
  89. $data['value'] = json_encode($value);
  90. $data['version'] = uniqid();
  91. return app('json')->success($id ? '修改成功' : '保存成功', ['id' => $this->services->saveInfo($id, $data)]);
  92. }
  93. public function delInfo($id)
  94. {
  95. $this->services->delInfo($id);
  96. return app('json')->success('删除成功');
  97. }
  98. public function setInfoStatus($id)
  99. {
  100. return app('json')->success($this->services->setInfoStatus($id));
  101. }
  102. public function getProduct()
  103. {
  104. $where = $this->request->getMore([
  105. ['cate_id', []], //搜索分类
  106. ['salesOrder', ''], //销量排序
  107. ['priceOrder', ''], //价格排序
  108. ['store_label_id', []], //标签ID
  109. ['ids', ''], //商品ID
  110. ]);
  111. $where['is_show'] = 1;
  112. $where['is_del'] = 0;
  113. if (is_string($where['ids']) && $where['ids'] != '') $where['ids'] = explode(',', $where['ids']);
  114. [$page, $limit] = $this->services->getPageValue();
  115. $list = app()->make(StoreProductServices::class)->getSearchList($where, $page, $limit, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price']);
  116. return app('json')->success($list);
  117. }
  118. public function updateName($id = 0)
  119. {
  120. [$name] = $this->request->postMore([
  121. ['name', '']
  122. ], true);
  123. if (!$name) return app('json')->fail('请输入名称');
  124. $this->services->updateName($id, $name);
  125. return app('json')->success('修改成功');
  126. }
  127. public function exportDIYData($id)
  128. {
  129. $value = $this->services->exportDIYData($id);
  130. $filename = 'DIY数据_' . date('YmdHis', time()) . '.txt';
  131. return app('json')->success('导出成功', ['value' => $value, 'filename' => $filename]);
  132. }
  133. public function importDIYData()
  134. {
  135. // 获取文件
  136. $file = $this->request->file('file');
  137. if (!$file) return app('json')->fail('请上传文件');
  138. // 获取文件的临时路径
  139. $tempPath = $file->getRealPath();
  140. // 使用文件流读取内容
  141. $content = file_get_contents($tempPath);
  142. // 保存内容
  143. $this->services->importDIYData($content);
  144. return app('json')->success('导入成功');
  145. }
  146. public function textField()
  147. {
  148. $user = [
  149. ['label' => '用户名称', 'value' => 'nickname'],
  150. ['label' => '用户id', 'value' => 'uid'],
  151. ['label' => '用户头像', 'value' => 'image'],
  152. ['label' => '商品收藏', 'value' => 'collection_num'],
  153. ['label' => '商品加购', 'value' => 'cart_num'],
  154. ['label' => '订单总数', 'value' => 'order_num'],
  155. ['label' => '我的积分', 'value' => 'integral'],
  156. ['label' => '我的余额', 'value' => 'now_money'],
  157. ['label' => '我的佣金', 'value' => 'brokerage_price'],
  158. ['label' => '未读消息', 'value' => 'unread_msg_num'],
  159. ];
  160. $article = [
  161. ['label' => '文章标题', 'value' => 'title'],
  162. ['label' => '文章id', 'value' => 'id'],
  163. ['label' => '文章封面', 'value' => 'image'],
  164. ['label' => '文章分类', 'value' => 'cid_name'],
  165. ['label' => '文章简介', 'value' => 'synopsis'],
  166. ['label' => '文章浏览量', 'value' => 'visit'],
  167. ['label' => '添加时间', 'value' => 'add_time'],
  168. ];
  169. $coupon = [
  170. ['label' => '优惠券名称', 'value' => 'coupon_title'],
  171. ['label' => '优惠券id', 'value' => 'id'],
  172. ['label' => '优惠券类型', 'value' => 'type'],
  173. ['label' => '优惠券面值', 'value' => 'coupon_price'],
  174. ['label' => '优惠券状态', 'value' => 'status'],
  175. ['label' => '领取时间', 'value' => 'receive_time'],
  176. ['label' => '使用时间', 'value' => 'use_time'],
  177. ['label' => '使用门槛', 'value' => 'use_min_price'],
  178. ['label' => '发放数量', 'value' => 'receive_count'],
  179. ['label' => '添加时间', 'value' => 'add_time'],
  180. ];
  181. $product = [
  182. ['label' => '商品名称', 'value' => 'store_name'],
  183. ['label' => '商品id', 'value' => 'id'],
  184. ['label' => '商品图片', 'value' => 'image'],
  185. ['label' => '商品简介', 'value' => 'store_info'],
  186. ['label' => '商品单位', 'value' => 'unit_name'],
  187. ['label' => '商品分类', 'value' => 'cate_name'],
  188. ['label' => '商品库存', 'value' => 'stock'],
  189. ['label' => '商品售价', 'value' => 'price'],
  190. ['label' => '商品最高售价', 'value' => 'max_price'],
  191. ['label' => '商品最低售价', 'value' => 'min_price'],
  192. ['label' => '商品原价', 'value' => 'ot_price'],
  193. ['label' => '商品最高原价', 'value' => 'max_ot_price'],
  194. ['label' => '商品最低原价', 'value' => 'min_ot_price'],
  195. ['label' => '商品起购数量', 'value' => 'min_qty'],
  196. ['label' => '商品销量', 'value' => 'sales'],
  197. ['label' => '商品访问量', 'value' => 'browse'],
  198. ['label' => '商品添加时间', 'value' => 'add_time'],
  199. ];
  200. return app('json')->success(compact('user', 'article', 'coupon', 'product'));
  201. }
  202. }