You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Common.php 9.7KB

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