Common.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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\admin;
  12. use app\services\order\StoreOrderRefundServices;
  13. use app\services\other\CityAreaServices;
  14. use app\services\product\sku\StoreProductAttrValueServices;
  15. use app\services\system\SystemAuthServices;
  16. use app\services\order\StoreOrderServices;
  17. use app\services\product\product\StoreProductServices;
  18. use app\services\product\product\StoreProductReplyServices;
  19. use app\services\user\UserExtractServices;
  20. use app\services\system\SystemMenusServices;
  21. use app\services\user\UserServices;
  22. use crmeb\services\CacheService;
  23. use crmeb\services\SystemConfigService;
  24. /**
  25. * 公共接口基类 主要存放公共接口
  26. * Class Common
  27. * @package app\controller\admin
  28. */
  29. class Common extends AuthController
  30. {
  31. /**
  32. * 获取logo
  33. * @param SystemConfigService $services
  34. * @return mixed
  35. */
  36. public function getLogo(SystemConfigService $services)
  37. {
  38. $data = $services->more(['site_logo', 'site_logo_square', 'site_name']);
  39. return $this->success($data);
  40. }
  41. /**
  42. * @return mixed
  43. */
  44. public function check_auth()
  45. {
  46. return $this->checkAuthDecrypt();
  47. }
  48. /**
  49. * @return mixed
  50. */
  51. public function auth()
  52. {
  53. return $this->getAuth();
  54. }
  55. /**
  56. * 查询购买版权
  57. * @return mixed
  58. */
  59. public function crmeb_copyright()
  60. {
  61. $this->__6j3nfcwmWqrsDx8F0MjZGeQyWvLsqeFXww();
  62. return $this->success('查询成功');
  63. }
  64. /**
  65. * 保存版权
  66. * @return mixed
  67. */
  68. public function saveCopyright()
  69. {
  70. $copyright = $this->request->post('copyright');
  71. $copyrightImg = $this->request->post('copyright_img');
  72. $this->__qsG71NREI01vix2OkjH($copyright, $copyrightImg);
  73. return $this->success('保存成功');
  74. }
  75. /**
  76. * 获取版权
  77. * @return mixed
  78. */
  79. public function getCopyright()
  80. {
  81. try {
  82. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  83. } catch (\Throwable $e) {
  84. $copyright = ['copyrightContext' => '', 'copyrightImage' => ''];
  85. }
  86. $copyright['version'] = get_crmeb_version();
  87. return $this->success($copyright);
  88. }
  89. /**
  90. * 申请授权
  91. * @return mixed
  92. */
  93. public function auth_apply(SystemAuthServices $services)
  94. {
  95. $version = get_crmeb_version();
  96. $data = $this->request->postMore([
  97. ['company_name', ''],
  98. ['domain_name', ''],
  99. ['order_id', ''],
  100. ['phone', ''],
  101. ['label', strripos($version, 'min') === false ? 3 : 2],
  102. ['captcha', ''],
  103. ]);
  104. if (!$data['company_name']) {
  105. return $this->fail('请填写公司名称');
  106. }
  107. if (!$data['domain_name']) {
  108. return $this->fail('请填写授权域名');
  109. }
  110. if (!$data['phone']) {
  111. return $this->fail('请填写手机号码');
  112. }
  113. if (!$data['order_id']) {
  114. return $this->fail('请填写订单id');
  115. }
  116. $datas = explode('.', $data['domain_name']);
  117. $n = count($datas);
  118. $preg = '/[\w].+\.(com|net|org|gov|edu)\.cn$/';
  119. if (($n > 2) && preg_match($preg, $data['domain_name'])) {
  120. //双后缀取后3位
  121. $domain_name = $datas[$n - 3] . '.' . $datas[$n - 2] . '.' . $datas[$n - 1];
  122. } else {
  123. //非双后缀取后两位
  124. $domain_name = $datas[$n - 2] . '.' . $datas[$n - 1];
  125. }
  126. $sec = trim(str_replace($domain_name, '', $data['domain_name']), '.');
  127. if ($sec) {
  128. if ($sec == 'www') {
  129. $data['domain_name'] = $domain_name;
  130. }
  131. }
  132. $header = $this->__k0dUcnKjRUs9lfEllqO9J($data['phone']);
  133. if ($header) {
  134. $headerData = ['Authori-zation:Bearer ' . $this->__k0dUcnKjRUs9lfEllqO9J($data['phone'])];
  135. } else {
  136. $headerData = false;
  137. }
  138. $services->authApply($data, $headerData);
  139. return $this->success("申请授权成功!");
  140. }
  141. /**
  142. * 首页头部统计数据
  143. * @return mixed
  144. */
  145. public function homeStatics()
  146. {
  147. /** @var StoreOrderServices $orderServices */
  148. $orderServices = app()->make(StoreOrderServices::class);
  149. $info = $orderServices->homeStatics();
  150. return $this->success(compact('info'));
  151. }
  152. /**
  153. * 订单图表
  154. */
  155. public function orderChart()
  156. {
  157. $cycle = $this->request->param('cycle') ?: 'thirtyday';//默认30天
  158. /** @var StoreOrderServices $orderServices */
  159. $orderServices = app()->make(StoreOrderServices::class);
  160. $chartdata = $orderServices->orderCharts($cycle);
  161. return $this->success($chartdata);
  162. }
  163. /**
  164. * 用户图表
  165. */
  166. public function userChart()
  167. {
  168. /** @var UserServices $uServices */
  169. $uServices = app()->make(UserServices::class);
  170. $chartdata = $uServices->userChart();
  171. return $this->success($chartdata);
  172. }
  173. /**
  174. * 交易额排行
  175. * @return mixed
  176. */
  177. public function purchaseRanking()
  178. {
  179. // /** @var StoreProductAttrValueServices $valueServices */
  180. // $valueServices = app()->make(StoreProductAttrValueServices::class);
  181. // $list = $valueServices->purchaseRanking();
  182. $list = [];
  183. return $this->success(compact('list'));
  184. }
  185. /**
  186. * 待办事统计
  187. * @return mixed
  188. */
  189. public function jnotice()
  190. {
  191. /** @var StoreOrderServices $orderServices */
  192. $orderServices = app()->make(StoreOrderServices::class);
  193. $orderNum = $orderServices->storeOrderCount();
  194. /** @var StoreProductServices $storeServices */
  195. $storeServices = app()->make(StoreProductServices::class);
  196. /** @var StoreProductReplyServices $replyServices */
  197. $replyServices = app()->make(StoreProductReplyServices::class);
  198. $commentNum = $replyServices->replyCount();
  199. /** @var UserExtractServices $extractServices */
  200. $extractServices = app()->make(UserExtractServices::class);
  201. $reflectNum = $extractServices->userExtractCount();//提现
  202. $newOrderId = $orderServices->newOrderId(1);
  203. /** @var StoreOrderRefundServices $refundServices */
  204. $refundServices = app()->make(StoreOrderRefundServices::class);
  205. $orderRefundNum = $refundServices->count(['is_cancel' => 0, 'refund_type' => [1, 2, 4, 5], 'store_id' => 0]);
  206. if (count($newOrderId)) $orderServices->update([['order_id', 'IN', $newOrderId]], ['is_remind' => 1]);
  207. $value = [];
  208. if ($orderNum) {
  209. $value[] = [
  210. 'title' => '您有' . $orderNum . '个待发货的订单',
  211. 'type' => 'bulb',
  212. 'url' => '/order/list?status=1'
  213. ];
  214. }
  215. $inventory = $storeServices->count(['is_police' => 1, 'status' => 5, 'pid' => 0, 'store_stock' => 0]);
  216. if ($inventory) {
  217. $value[] = [
  218. 'title' => '您有' . $inventory . '个商品库存预警',
  219. 'type' => 'information',
  220. 'url' => '/product/product_list?type=5',
  221. ];
  222. }
  223. if ($commentNum) {
  224. $value[] = [
  225. 'title' => '您有' . $commentNum . '条评论待回复',
  226. 'type' => 'bulb',
  227. 'url' => '/product/product_reply?is_reply=0'
  228. ];
  229. }
  230. if ($reflectNum) {
  231. $value[] = [
  232. 'title' => '您有' . $reflectNum . '个提现申请待审核',
  233. 'type' => 'bulb',
  234. 'url' => '/finance/user_extract/index?status=0',
  235. ];
  236. }
  237. if ($orderRefundNum) {
  238. $value[] = [
  239. 'title' => '您有' . $orderRefundNum . '个售后订单待处理',
  240. 'type' => 'bulb',
  241. 'url' => '/order/refund'
  242. ];
  243. }
  244. return $this->success($this->noticeData($value));
  245. }
  246. /**
  247. * 消息返回格式
  248. * @param array $data
  249. * @return array
  250. */
  251. public function noticeData(array $data): array
  252. {
  253. // 消息图标
  254. $iconColor = [
  255. // 邮件 消息
  256. 'mail' => [
  257. 'icon' => 'md-mail',
  258. 'color' => '#3391e5'
  259. ],
  260. // 普通 消息
  261. 'bulb' => [
  262. 'icon' => 'md-bulb',
  263. 'color' => '#87d068'
  264. ],
  265. // 警告 消息
  266. 'information' => [
  267. 'icon' => 'md-information',
  268. 'color' => '#fe5c57'
  269. ],
  270. // 关注 消息
  271. 'star' => [
  272. 'icon' => 'md-star',
  273. 'color' => '#ff9900'
  274. ],
  275. // 申请 消息
  276. 'people' => [
  277. 'icon' => 'md-people',
  278. 'color' => '#f06292'
  279. ],
  280. ];
  281. // 消息类型
  282. $type = array_keys($iconColor);
  283. // 默认数据格式
  284. $default = [
  285. 'icon' => 'md-bulb',
  286. 'iconColor' => '#87d068',
  287. 'title' => '',
  288. 'url' => '',
  289. 'type' => 'bulb',
  290. 'read' => 0,
  291. 'time' => 0
  292. ];
  293. $value = [];
  294. foreach ($data as $item) {
  295. $val = array_merge($default, $item);
  296. if (isset($item['type']) && in_array($item['type'], $type)) {
  297. $val['type'] = $item['type'];
  298. $val['iconColor'] = $iconColor[$item['type']]['color'] ?? '';
  299. $val['icon'] = $iconColor[$item['type']]['icon'] ?? '';
  300. }
  301. $value[] = $val;
  302. }
  303. return $value;
  304. }
  305. /**
  306. * 格式化菜单
  307. * @return mixed
  308. * @throws \think\db\exception\DataNotFoundException
  309. * @throws \think\db\exception\DbException
  310. * @throws \think\db\exception\ModelNotFoundException
  311. */
  312. public function menusList()
  313. {
  314. $cahcheKey = md5('admin_common_menu_list');
  315. $list = CacheService::redisHandler()->get($cahcheKey);
  316. if (!$list) {
  317. /** @var SystemMenusServices $menusServices */
  318. $menusServices = app()->make(SystemMenusServices::class);
  319. $menus = $menusServices->getSearchList();
  320. $counts = $menusServices->getColumn([
  321. ['is_show', '=', 1],
  322. ['auth_type', '=', 1],
  323. ['is_del', '=', 0],
  324. ['is_show_path', '=', 0],
  325. ], 'pid');
  326. $data = [];
  327. foreach ($menus as $key => $item) {
  328. $pid = $item->getData('pid');
  329. $data[$key] = json_decode($item, true);
  330. $data[$key]['pid'] = $pid;
  331. if (in_array($item->id, $counts)) {
  332. $data[$key]['type'] = 1;
  333. } else {
  334. $data[$key]['type'] = 0;
  335. }
  336. $data[$key]['menu_path'] = preg_replace('/^\/admin/', '', $item['menu_path']);
  337. }
  338. $list = sort_list_tier($data);
  339. CacheService::redisHandler()->set($cahcheKey, $list, 86400);
  340. }
  341. return app('json')->success($list);
  342. }
  343. /**
  344. * @param CityAreaServices $services
  345. * @return mixed
  346. */
  347. public function city(CityAreaServices $services)
  348. {
  349. $pid = $this->request->get('pid', 0);
  350. $type = $this->request->get('type', 0);
  351. return $this->success($services->getCityTreeList((int)$pid, $type));
  352. }
  353. }