Common.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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\store;
  12. use app\Request;
  13. use app\services\order\OtherOrderServices;
  14. use app\services\order\store\BranchOrderServices;
  15. use app\services\order\StoreOrderRefundServices;
  16. use app\services\order\StoreOrderServices;
  17. use app\services\other\CityAreaServices;
  18. use app\services\product\branch\StoreBranchProductServices;
  19. use app\services\product\product\StoreProductReplyServices;
  20. use app\services\store\SystemStoreServices;
  21. use app\services\store\SystemStoreStaffServices;
  22. use app\services\system\SystemMenusServices;
  23. use app\services\user\UserRechargeServices;
  24. /**
  25. * 公共接口基类 主要存放公共接口
  26. * Class Common
  27. * @package app\controller\admin
  28. */
  29. class Common extends AuthController
  30. {
  31. /**
  32. * 获取logo
  33. * @param SystemStoreServices $storeServices
  34. * @return mixed
  35. */
  36. public function getLogo(SystemStoreServices $storeServices)
  37. {
  38. $store = $storeServices->get((int)$this->storeId, ['id', 'image', 'name']);
  39. return $this->success([
  40. 'logo' => $store && isset($store['image']) && $store['image'] ? $store['image'] : sys_config('site_logo'),
  41. 'logo_square' => $store && isset($store['image']) && $store['image'] ? $store['image'] : sys_config('site_logo_square'),
  42. 'site_name' => $store && isset($store['name']) && $store['name'] ? $store['name'] : sys_config('site_name')
  43. ]);
  44. }
  45. /**
  46. * 获取门店配置
  47. * @param SystemStoreServices $storeServices
  48. * @return mixed
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getConfig(SystemStoreServices $storeServices)
  54. {
  55. $store = $storeServices->get((int)$this->storeId, ['id', 'product_status']);
  56. return $this->success([
  57. 'tengxun_map_key' => sys_config('tengxun_map_key'),
  58. 'open_erp' => !!sys_config('erp_open'),
  59. 'product_status' => $store['product_status'] ?? 1
  60. ]);
  61. }
  62. /**
  63. * @param CityAreaServices $services
  64. * @return mixed
  65. */
  66. public function city(CityAreaServices $services, $pid = 0)
  67. {
  68. return $this->success($services->getCityTreeList((int)$pid));
  69. }
  70. /**
  71. * 格式化菜单
  72. * @return mixed
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public function menusList()
  78. {
  79. /** @var SystemMenusServices $menusServices */
  80. $menusServices = app()->make(SystemMenusServices::class);
  81. $list = $menusServices->getSearchList(2);
  82. $counts = $menusServices->getColumn([
  83. ['type', 2],
  84. ['is_show', '=', 1],
  85. ['auth_type', '=', 1],
  86. ['is_del', '=', 0],
  87. ['is_show_path', '=', 0],
  88. ], 'pid');
  89. $data = [];
  90. foreach ($list as $key => $item) {
  91. $pid = $item->getData('pid');
  92. $data[$key] = json_decode($item, true);
  93. $data[$key]['pid'] = $pid;
  94. if (in_array($item->id, $counts)) {
  95. $data[$key]['type'] = 1;
  96. } else {
  97. $data[$key]['type'] = 0;
  98. }
  99. $data[$key]['menu_path'] = preg_replace('/^\/store/', '', $item['menu_path']);
  100. }
  101. return app('json')->success(sort_list_tier($data));
  102. }
  103. /**
  104. * 首页运营头部统计
  105. * @param Request $request
  106. * @param BranchOrderServices $orderServices
  107. * @return mixed
  108. */
  109. public function homeStatics(Request $request, BranchOrderServices $orderServices)
  110. {
  111. [$time] = $request->getMore([
  112. ['data', '', '', 'time']
  113. ], true);
  114. $time = $orderServices->timeHandle($time);
  115. return app('json')->success($orderServices->homeStatics((int)$this->storeId, $time));
  116. }
  117. /**
  118. * 首页营业趋势图表
  119. * @param Request $request
  120. * @param BranchOrderServices $orderServices
  121. * @return mixed
  122. */
  123. public function operateChart(Request $request, BranchOrderServices $orderServices)
  124. {
  125. [$time] = $request->getMore([
  126. ['data', '', '', 'time']
  127. ], true);
  128. $time = $orderServices->timeHandle($time, true);
  129. return app('json')->success($orderServices->operateChart((int)$this->storeId, $time));
  130. }
  131. /**
  132. * 首页交易统计
  133. * @param Request $request
  134. * @param BranchOrderServices $orderServices
  135. * @return mixed
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\DbException
  138. * @throws \think\db\exception\ModelNotFoundException
  139. */
  140. public function orderChart(Request $request, BranchOrderServices $orderServices)
  141. {
  142. [$time] = $request->getMore([
  143. ['data', '', '', 'time']
  144. ], true);
  145. $time = $orderServices->timeHandle($time);
  146. return $this->success($orderServices->orderChart((int)$this->storeId, $time));
  147. }
  148. /**
  149. * 首页店员统计
  150. * @param Request $request
  151. * @param SystemStoreStaffServices $staffServices
  152. * @return mixed
  153. */
  154. public function staffChart(Request $request, SystemStoreStaffServices $staffServices)
  155. {
  156. [$time] = $request->getMore([
  157. ['data', '', '', 'time']
  158. ], true);
  159. $time = $staffServices->timeHandle($time);
  160. return $this->success($staffServices->staffChart((int)$this->storeId, $time));
  161. }
  162. /**
  163. * 待办事统计
  164. * @return mixed
  165. */
  166. public function jnotice()
  167. {
  168. /** @var StoreOrderServices $orderServices */
  169. $orderServices = app()->make(StoreOrderServices::class);
  170. $orderNum = $orderServices->storeOrderCount((int)$this->storeId, 7);
  171. $store_stock = sys_config('store_stock');
  172. if ($store_stock < 0) $store_stock = 2;
  173. /** @var StoreBranchProductServices $storeServices */
  174. $storeServices = app()->make(StoreBranchProductServices::class);
  175. $inventory = $storeServices->count(['store_id' => $this->storeId, 'is_police' => 1, 'status' => 5, 'store_stock' => $store_stock]);//警戒库存
  176. /** @var StoreProductReplyServices $replyServices */
  177. $replyServices = app()->make(StoreProductReplyServices::class);
  178. $commentNum = $replyServices->replyCount(1, (int)$this->storeId);
  179. /** @var StoreOrderRefundServices $refundServices */
  180. $refundServices = app()->make(StoreOrderRefundServices::class);
  181. $orderRefundNum = $refundServices->count(['is_cancel' => 0, 'refund_type' => [1, 2, 4, 5], 'store_id' => $this->storeId]);
  182. $value = [];
  183. if ($orderNum) {
  184. $value[] = [
  185. 'title' => '您有' . $orderNum . '个待发货的订单',
  186. 'type' => 'bulb',
  187. 'url' => '/' . config('admin.store_prefix') . '/order/index?type=7&status=1'
  188. ];
  189. }
  190. if ($inventory) {
  191. $value[] = [
  192. 'title' => '您有' . $inventory . '个商品库存预警',
  193. 'type' => 'information',
  194. 'url' => '/' . config('admin.store_prefix') . '/product/index?type=5',
  195. ];
  196. }
  197. if ($commentNum) {
  198. $value[] = [
  199. 'title' => '您有' . $commentNum . '条评论待回复',
  200. 'type' => 'bulb',
  201. 'url' => '/' . config('admin.store_prefix') . '/product/product_reply?is_reply=0'
  202. ];
  203. }
  204. if ($orderRefundNum) {
  205. $value[] = [
  206. 'title' => '您有' . $orderRefundNum . '个售后订单待处理',
  207. 'type' => 'bulb',
  208. 'url' => '/' . config('admin.store_prefix') . '/order/refund'
  209. ];
  210. }
  211. return $this->success($this->noticeData($value));
  212. }
  213. /**
  214. * 消息返回格式
  215. * @param array $data
  216. * @return array
  217. */
  218. public function noticeData(array $data): array
  219. {
  220. // 消息图标
  221. $iconColor = [
  222. // 邮件 消息
  223. 'mail' => [
  224. 'icon' => 'md-mail',
  225. 'color' => '#3391e5'
  226. ],
  227. // 普通 消息
  228. 'bulb' => [
  229. 'icon' => 'md-bulb',
  230. 'color' => '#87d068'
  231. ],
  232. // 警告 消息
  233. 'information' => [
  234. 'icon' => 'md-information',
  235. 'color' => '#fe5c57'
  236. ],
  237. // 关注 消息
  238. 'star' => [
  239. 'icon' => 'md-star',
  240. 'color' => '#ff9900'
  241. ],
  242. // 申请 消息
  243. 'people' => [
  244. 'icon' => 'md-people',
  245. 'color' => '#f06292'
  246. ],
  247. ];
  248. // 消息类型
  249. $type = array_keys($iconColor);
  250. // 默认数据格式
  251. $default = [
  252. 'icon' => 'md-bulb',
  253. 'iconColor' => '#87d068',
  254. 'title' => '',
  255. 'url' => '',
  256. 'type' => 'bulb',
  257. 'read' => 0,
  258. 'time' => 0
  259. ];
  260. $value = [];
  261. foreach ($data as $item) {
  262. $val = array_merge($default, $item);
  263. if (isset($item['type']) && in_array($item['type'], $type)) {
  264. $val['type'] = $item['type'];
  265. $val['iconColor'] = $iconColor[$item['type']]['color'] ?? '';
  266. $val['icon'] = $iconColor[$item['type']]['icon'] ?? '';
  267. }
  268. $value[] = $val;
  269. }
  270. return $value;
  271. }
  272. /**
  273. * 轮询后台扫码订单状态
  274. * @param Request $request
  275. * @param $type
  276. * @return mixed
  277. */
  278. public function checkOrderStatus(Request $request, $type)
  279. {
  280. [$order_id, $end_time] = $request->getMore([
  281. ['order_id', ''],
  282. ['end_time', 0],
  283. ], true);
  284. switch ($type) {
  285. case 1://recharge
  286. /** @var UserRechargeServices $userRecharge */
  287. $userRecharge = app()->make(UserRechargeServices::class);
  288. $data['status'] = (bool)$userRecharge->count(['order_id' => $order_id, 'paid' => 1]);
  289. break;
  290. case 2://svip
  291. /** @var OtherOrderServices $otherOrderServices */
  292. $otherOrderServices = app()->make(OtherOrderServices::class);
  293. $data['status'] = (bool)$otherOrderServices->count(['order_id' => $order_id, 'paid' => 1]);
  294. break;
  295. case 3://订单
  296. $storeOrderServices = app()->make(StoreOrderServices::class);
  297. $data['status'] = (bool)$storeOrderServices->count(['order_id' => $order_id, 'paid' => 1]);
  298. break;
  299. default:
  300. return app('json')->fail('暂不支持该类型订单查询');
  301. }
  302. $time = $end_time - time();
  303. $data['time'] = $time > 0 ? $time : 0;
  304. return app('json')->successful($data);
  305. }
  306. /**
  307. * 获取版权
  308. * @return mixed
  309. */
  310. public function getCopyright()
  311. {
  312. try {
  313. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  314. } catch (\Throwable $e) {
  315. $copyright = ['copyrightContext' => '', 'copyrightImage' => ''];
  316. }
  317. $copyright['version'] = get_crmeb_version();
  318. $copyright['prefix'] = config('admin.cashier_prefix');
  319. $copyright['extract_min_price'] = sys_config('store_extract_min_price');
  320. $copyright['extract_max_price'] = sys_config('store_extract_max_price');
  321. return $this->success($copyright);
  322. }
  323. }