Serve.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\serve;
  12. use app\adminapi\controller\AuthController;
  13. use app\adminapi\validate\serve\ExpressValidata;
  14. use app\adminapi\validate\serve\MealValidata;
  15. use app\adminapi\validate\serve\ServeValidata;
  16. use app\services\system\config\SystemConfigServices;
  17. use crmeb\services\CacheService;
  18. use app\services\serve\ServeServices;
  19. use think\facade\App;
  20. /**
  21. * Class Serve
  22. * @package app\adminapi\controller\v1\serve
  23. */
  24. class Serve extends AuthController
  25. {
  26. /**
  27. * Serve constructor.
  28. * @param App $app
  29. * @param ServeServices $services
  30. */
  31. public function __construct(App $app, ServeServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 检测登录
  38. * @return mixed
  39. */
  40. public function is_login()
  41. {
  42. $sms_info = CacheService::get('sms_account');
  43. if ($sms_info) {
  44. return app('json')->success(['status' => true, 'info' => $sms_info]);
  45. } else {
  46. return app('json')->success(['status' => false]);
  47. }
  48. }
  49. /**
  50. * 获取套餐列表
  51. * @param string $type
  52. * @return mixed
  53. */
  54. public function mealList(string $type)
  55. {
  56. $res = $this->services->user()->mealList($type);
  57. if ($res) {
  58. return app('json')->success($res);
  59. } else {
  60. return app('json')->fail(400173);
  61. }
  62. }
  63. /**
  64. * 获取支付码
  65. * @return mixed
  66. */
  67. public function payMeal()
  68. {
  69. $data = $this->request->postMore([
  70. ['meal_id', ''],
  71. ['price', ''],
  72. ['num', ''],
  73. ['type', ''],
  74. ['pay_type', ''],
  75. ]);
  76. $openInfo = $this->services->user()->getUser();
  77. if (!$openInfo) app('json')->fail(400174);
  78. switch ($data['type']) {
  79. case "sms" :
  80. if (!$openInfo['sms']['open']) return app('json')->fail(400175);
  81. break;
  82. case "query" :
  83. if (!$openInfo['query']['open']) return app('json')->fail(400176);
  84. break;
  85. case "dump" :
  86. if (!$openInfo['dump']['open']) return app('json')->fail(400177);
  87. break;
  88. case "copy" :
  89. if (!$openInfo['copy']['open']) return app('json')->fail(400178);
  90. break;
  91. }
  92. $this->validate($data, MealValidata::class);
  93. $res = $this->services->user()->payMeal($data);
  94. if ($res) {
  95. return app('json')->success($res);
  96. } else {
  97. return app('json')->fail(400174);
  98. }
  99. }
  100. /**
  101. * 开通打印电子面单
  102. * @return mixed
  103. */
  104. public function openExpress()
  105. {
  106. $data = $this->request->postMore([
  107. ['com', ''],
  108. ['temp_id', ''],
  109. ['to_name', ''],
  110. ['to_tel', ''],
  111. ['to_address', ''],
  112. ['siid', ''],
  113. ]);
  114. $this->validate($data, ExpressValidata::class);
  115. /** @var SystemConfigServices $systemConfigService */
  116. $systemConfigService = app()->make(SystemConfigServices::class);
  117. $systemConfigService->saveExpressInfo($data);
  118. $this->services->express()->open();
  119. return app('json')->success(100044);
  120. }
  121. /**
  122. * 获取用户信息,用户信息内包含是否开通服务字段
  123. * @return mixed
  124. */
  125. public function getUserInfo()
  126. {
  127. return app('json')->success($this->services->user()->getUser());
  128. }
  129. /**
  130. * 查询记录
  131. * @return mixed
  132. */
  133. public function getRecord()
  134. {
  135. [$page, $limit, $type] = $this->request->getMore([
  136. [['page', 'd'], 0],
  137. [['limit', 'd'], 10],
  138. [['type', 'd'], 0],
  139. ], true);
  140. return app('json')->success($this->services->user()->record($page, $limit, $type));
  141. }
  142. /**
  143. * 开通服务
  144. * @param int $type
  145. * @return mixed
  146. */
  147. public function openServe($type = 0)
  148. {
  149. if ($type) {
  150. $this->services->copy()->open();
  151. } else {
  152. $this->services->express()->open();
  153. }
  154. return app('json')->success(100044);
  155. }
  156. /**
  157. * 修改密码
  158. * @return mixed
  159. */
  160. public function modify()
  161. {
  162. $data = $this->request->postMore([
  163. ['account', ''],
  164. ['password', ''],
  165. ['phone', ''],
  166. ['verify_code', ''],
  167. ]);
  168. $this->validate($data, ServeValidata::class);
  169. $data['password'] = md5($data['password']);
  170. $this->services->user()->modify($data);
  171. CacheService::delete('sms_account');
  172. return app('json')->success(100001);
  173. }
  174. /**
  175. * 修改手机号
  176. * @return mixed
  177. */
  178. public function updatePhone()
  179. {
  180. $data = $this->request->postMore([
  181. ['account', ''],
  182. ['phone', ''],
  183. ['verify_code', ''],
  184. ]);
  185. $this->validate($data, ServeValidata::class, 'phone');
  186. $this->services->user()->modifyPhone($data);
  187. CacheService::delete('sms_account');
  188. return app('json')->success(100001);
  189. }
  190. }