Common.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. return $this->success($data);
  104. }
  105. /**
  106. * 营业趋势图表
  107. * @param SupplierOrderServices $orderServices
  108. * @return mixed
  109. */
  110. public function orderChart(SupplierOrderServices $orderServices)
  111. {
  112. [$time] = $this->request->getMore([
  113. ['data', '', '', 'time']
  114. ], true);
  115. $time = $orderServices->timeHandle($time, true);
  116. $data = $orderServices->orderCharts((int)$this->supplierId, $time);
  117. return $this->success($data);
  118. }
  119. /**
  120. * 订单类型分析
  121. * @param SupplierOrderServices $orderServices
  122. * @return mixed
  123. */
  124. public function orderType(SupplierOrderServices $orderServices)
  125. {
  126. [$time] = $this->request->getMore([
  127. ['data', '', '', 'time']
  128. ], true);
  129. $time = $orderServices->timeHandle($time, true);
  130. $data = $orderServices->getOrderType((int)$this->supplierId, $time);
  131. return $this->success($data);
  132. }
  133. /**
  134. * 订单来源分析
  135. * @param SupplierOrderServices $orderServices
  136. * @return mixed
  137. */
  138. public function orderChannel(SupplierOrderServices $orderServices)
  139. {
  140. [$time] = $this->request->getMore([
  141. ['data', '', '', 'time']
  142. ], true);
  143. $time = $orderServices->timeHandle($time, true);
  144. $data = $orderServices->getOrderChannel((int)$this->supplierId, $time);
  145. return $this->success($data);
  146. }
  147. /**
  148. * 待办事统计
  149. * @return mixed
  150. */
  151. public function jnotice()
  152. {
  153. /** @var StoreOrderServices $orderServices */
  154. $orderServices = app()->make(StoreOrderServices::class);
  155. $orderNum = $orderServices->storeOrderCount((int)$this->supplierId, -1, 'supplier_id');
  156. /** @var StoreOrderRefundServices $refundServices */
  157. $refundServices = app()->make(StoreOrderRefundServices::class);
  158. $orderRefundNum = $refundServices->count(['is_cancel' => 0, 'refund_type' => [1, 2, 4, 5], 'supplier_id' => $this->supplierId]);
  159. $value = [];
  160. if ($orderNum > 0) {
  161. $value[] = [
  162. 'title' => '您有' . $orderNum . '个待发货的订单',
  163. 'type' => 'bulb',
  164. 'url' => '/' . config('admin.supplier_prefix') . '/order/list?type=7&status=1'
  165. ];
  166. }
  167. if ($orderRefundNum) {
  168. $value[] = [
  169. 'title' => '您有' . $orderRefundNum . '个售后订单待处理',
  170. 'type' => 'bulb',
  171. 'url' => '/' . config('admin.supplier_prefix') . '/order/refund'
  172. ];
  173. }
  174. return $this->success($this->noticeData($value));
  175. }
  176. /**
  177. * 消息返回格式
  178. * @param array $data
  179. * @return array
  180. */
  181. public function noticeData(array $data): array
  182. {
  183. // 消息图标
  184. $iconColor = [
  185. // 邮件 消息
  186. 'mail' => [
  187. 'icon' => 'md-mail',
  188. 'color' => '#3391e5'
  189. ],
  190. // 普通 消息
  191. 'bulb' => [
  192. 'icon' => 'md-bulb',
  193. 'color' => '#87d068'
  194. ],
  195. // 警告 消息
  196. 'information' => [
  197. 'icon' => 'md-information',
  198. 'color' => '#fe5c57'
  199. ],
  200. // 关注 消息
  201. 'star' => [
  202. 'icon' => 'md-star',
  203. 'color' => '#ff9900'
  204. ],
  205. // 申请 消息
  206. 'people' => [
  207. 'icon' => 'md-people',
  208. 'color' => '#f06292'
  209. ],
  210. ];
  211. // 消息类型
  212. $type = array_keys($iconColor);
  213. // 默认数据格式
  214. $default = [
  215. 'icon' => 'md-bulb',
  216. 'iconColor' => '#87d068',
  217. 'title' => '',
  218. 'url' => '',
  219. 'type' => 'bulb',
  220. 'read' => 0,
  221. 'time' => 0
  222. ];
  223. $value = [];
  224. foreach ($data as $item) {
  225. $val = array_merge($default, $item);
  226. if (isset($item['type']) && in_array($item['type'], $type)) {
  227. $val['type'] = $item['type'];
  228. $val['iconColor'] = $iconColor[$item['type']]['color'] ?? '';
  229. $val['icon'] = $iconColor[$item['type']]['icon'] ?? '';
  230. }
  231. $value[] = $val;
  232. }
  233. return $value;
  234. }
  235. /**
  236. * 获取版权
  237. * @return mixed
  238. */
  239. public function getCopyright()
  240. {
  241. try {
  242. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  243. } catch (\Throwable $e) {
  244. $copyright = ['copyrightContext' => '', 'copyrightImage' => ''];
  245. }
  246. $copyright['version'] = get_crmeb_version();
  247. $copyright['extract_min_price'] = sys_config('supplier_extract_min_price');
  248. $copyright['extract_max_price'] = sys_config('supplier_extract_max_price');
  249. return $this->success($copyright);
  250. }
  251. }