Common.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\supplier;
  12. use app\services\order\StoreOrderRefundServices;
  13. use app\services\order\StoreOrderServices;
  14. use app\services\other\CityAreaServices;
  15. use app\services\order\supplier\SupplierOrderServices;
  16. use app\services\supplier\SystemSupplierServices;
  17. use app\services\system\SystemMenusServices;
  18. /**
  19. * 公共接口基类 主要存放公共接口
  20. * Class Common
  21. * @package app\controller\admin
  22. */
  23. class Common extends AuthController
  24. {
  25. /**
  26. * 获取logo
  27. * @param SystemSupplierServices $supplierServices
  28. * @return mixed
  29. */
  30. public function getLogo(SystemSupplierServices $supplierServices)
  31. {
  32. $supplier = $supplierServices->get((int)$this->supplierId, ['id', 'name']);
  33. return $this->success([
  34. 'logo' => sys_config('site_logo'),
  35. 'logo_square' => sys_config('site_logo_square'),
  36. 'site_name' => $supplier && isset($supplier['name']) && $supplier['name'] ? $supplier['name'] : sys_config('site_name')
  37. ]);
  38. }
  39. /**
  40. * @return mixed
  41. */
  42. public function getConfig()
  43. {
  44. return $this->success([
  45. 'tengxun_map_key' => sys_config('tengxun_map_key'),
  46. 'open_erp' => !!sys_config('erp_open')
  47. ]);
  48. }
  49. /**
  50. * 省市区信息
  51. * @param CityAreaServices $services
  52. * @return mixed
  53. */
  54. public function city(CityAreaServices $services, $pid = 0)
  55. {
  56. return $this->success($services->getCityTreeList((int)$pid));
  57. }
  58. /**
  59. * 格式化菜单
  60. * @return mixed
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function menusList()
  66. {
  67. /** @var SystemMenusServices $menusServices */
  68. $menusServices = app()->make(SystemMenusServices::class);
  69. $list = $menusServices->getSearchList(4);
  70. $counts = $menusServices->getColumn([
  71. ['type', 3],
  72. ['is_show', '=', 1],
  73. ['auth_type', '=', 1],
  74. ['is_del', '=', 0],
  75. ['is_show_path', '=', 0],
  76. ], 'pid');
  77. $data = [];
  78. foreach ($list as $key => $item) {
  79. $pid = $item->getData('pid');
  80. $data[$key] = json_decode($item, true);
  81. $data[$key]['pid'] = $pid;
  82. if (in_array($item->id, $counts)) {
  83. $data[$key]['type'] = 1;
  84. } else {
  85. $data[$key]['type'] = 0;
  86. }
  87. $data[$key]['menu_path'] = preg_replace('/^\/cashier/', '', $item['menu_path']);
  88. }
  89. return $this->success(sort_list_tier($data));
  90. }
  91. /**
  92. * 首页运营头部统计
  93. * @param SupplierOrderServices $orderServices
  94. * @return mixed
  95. */
  96. public function homeStatics(SupplierOrderServices $orderServices)
  97. {
  98. [$time] = $this->request->getMore([
  99. ['data', '', '', 'time']
  100. ], true);
  101. $time = $orderServices->timeHandle($time, true);
  102. $data = $orderServices->homeStatics((int)$this->supplierId, $time);
  103. $data['supplier'] = $this->supplierInfo;
  104. return $this->success($data);
  105. }
  106. /**
  107. * 营业趋势图表
  108. * @param SupplierOrderServices $orderServices
  109. * @return mixed
  110. */
  111. public function orderChart(SupplierOrderServices $orderServices)
  112. {
  113. [$time] = $this->request->getMore([
  114. ['data', '', '', 'time']
  115. ], true);
  116. $time = $orderServices->timeHandle($time, true);
  117. $data = $orderServices->orderCharts((int)$this->supplierId, $time);
  118. return $this->success($data);
  119. }
  120. /**
  121. * 订单类型分析
  122. * @param SupplierOrderServices $orderServices
  123. * @return mixed
  124. */
  125. public function orderType(SupplierOrderServices $orderServices)
  126. {
  127. [$time] = $this->request->getMore([
  128. ['data', '', '', 'time']
  129. ], true);
  130. $time = $orderServices->timeHandle($time, true);
  131. $data = $orderServices->getOrderType((int)$this->supplierId, $time);
  132. return $this->success($data);
  133. }
  134. /**
  135. * 订单来源分析
  136. * @param SupplierOrderServices $orderServices
  137. * @return mixed
  138. */
  139. public function orderChannel(SupplierOrderServices $orderServices)
  140. {
  141. [$time] = $this->request->getMore([
  142. ['data', '', '', 'time']
  143. ], true);
  144. $time = $orderServices->timeHandle($time, true);
  145. $data = $orderServices->getOrderChannel((int)$this->supplierId, $time);
  146. return $this->success($data);
  147. }
  148. /**
  149. * 待办事统计
  150. * @return mixed
  151. */
  152. public function jnotice()
  153. {
  154. /** @var StoreOrderServices $orderServices */
  155. $orderServices = app()->make(StoreOrderServices::class);
  156. $orderNum = $orderServices->storeOrderCount((int)$this->supplierId, -1, 'supplier_id');
  157. /** @var StoreOrderRefundServices $refundServices */
  158. $refundServices = app()->make(StoreOrderRefundServices::class);
  159. $orderRefundNum = $refundServices->count(['is_cancel' => 0, 'refund_type' => [1, 2, 4, 5], 'supplier_id' => $this->supplierId]);
  160. $value = [];
  161. if ($orderNum > 0) {
  162. $value[] = [
  163. 'title' => '您有' . $orderNum . '个待发货的订单',
  164. 'type' => 'bulb',
  165. 'url' => '/' . config('admin.supplier_prefix') . '/order/list?type=7&status=1'
  166. ];
  167. }
  168. if ($orderRefundNum) {
  169. $value[] = [
  170. 'title' => '您有' . $orderRefundNum . '个售后订单待处理',
  171. 'type' => 'bulb',
  172. 'url' => '/' . config('admin.supplier_prefix') . '/order/refund'
  173. ];
  174. }
  175. return $this->success($this->noticeData($value));
  176. }
  177. /**
  178. * 消息返回格式
  179. * @param array $data
  180. * @return array
  181. */
  182. public function noticeData(array $data): array
  183. {
  184. // 消息图标
  185. $iconColor = [
  186. // 邮件 消息
  187. 'mail' => [
  188. 'icon' => 'md-mail',
  189. 'color' => '#3391e5'
  190. ],
  191. // 普通 消息
  192. 'bulb' => [
  193. 'icon' => 'md-bulb',
  194. 'color' => '#87d068'
  195. ],
  196. // 警告 消息
  197. 'information' => [
  198. 'icon' => 'md-information',
  199. 'color' => '#fe5c57'
  200. ],
  201. // 关注 消息
  202. 'star' => [
  203. 'icon' => 'md-star',
  204. 'color' => '#ff9900'
  205. ],
  206. // 申请 消息
  207. 'people' => [
  208. 'icon' => 'md-people',
  209. 'color' => '#f06292'
  210. ],
  211. ];
  212. // 消息类型
  213. $type = array_keys($iconColor);
  214. // 默认数据格式
  215. $default = [
  216. 'icon' => 'md-bulb',
  217. 'iconColor' => '#87d068',
  218. 'title' => '',
  219. 'url' => '',
  220. 'type' => 'bulb',
  221. 'read' => 0,
  222. 'time' => 0
  223. ];
  224. $value = [];
  225. foreach ($data as $item) {
  226. $val = array_merge($default, $item);
  227. if (isset($item['type']) && in_array($item['type'], $type)) {
  228. $val['type'] = $item['type'];
  229. $val['iconColor'] = $iconColor[$item['type']]['color'] ?? '';
  230. $val['icon'] = $iconColor[$item['type']]['icon'] ?? '';
  231. }
  232. $value[] = $val;
  233. }
  234. return $value;
  235. }
  236. /**
  237. * 获取版权
  238. * @return mixed
  239. */
  240. public function getCopyright()
  241. {
  242. try {
  243. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  244. } catch (\Throwable $e) {
  245. $copyright = ['copyrightContext' => '', 'copyrightImage' => ''];
  246. }
  247. $copyright['version'] = get_crmeb_version();
  248. $copyright['extract_min_price'] = sys_config('supplier_extract_min_price');
  249. $copyright['extract_max_price'] = sys_config('supplier_extract_max_price');
  250. return $this->success($copyright);
  251. }
  252. }