ServiceLogic.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\logic;
  15. use app\common\cache\WebScanLoginCache;
  16. use app\common\logic\BaseLogic;
  17. use app\api\service\{UserTokenService, WechatUserService};
  18. use app\common\enum\{LoginEnum, PayEnum, user\UserTerminalEnum, YesNoEnum};
  19. use app\common\service\{
  20. ConfigService,
  21. FileService,
  22. wechat\WeChatConfigService,
  23. wechat\WeChatMnpService,
  24. wechat\WeChatOaService,
  25. wechat\WeChatRequestService
  26. };
  27. use app\common\model\agricultural_machinery\UserService;
  28. use app\common\model\agricultural_machinery\ServiceCategory;
  29. use app\common\model\ServiceCharge;
  30. use app\common\model\asset\AssetArea;
  31. use app\common\model\recharge\RechargeOrder;
  32. use app\common\model\user\{User, UserAuth};
  33. use think\facade\{Db, Config};
  34. /**
  35. * 服务商逻辑
  36. * Class LoginLogic
  37. * @package app\api\logic
  38. */
  39. class ServiceLogic extends BaseLogic
  40. {
  41. /**
  42. * @notes 入驻
  43. * @param array $params
  44. * @return bool
  45. * @author 段誉
  46. * @date 2022/9/7 15:37
  47. */
  48. public static function Settled(array $params)
  49. {
  50. Db::startTrans();
  51. try {
  52. $result = UserService::create([
  53. 'user_id' => $params['user_id'],
  54. 'type' => $params['type'] ?? 1,
  55. 'name' => $params['name'],
  56. 'mobile' => $params['mobile'],
  57. 'agricultural_machinery_model' =>$params['agricultural_machinery_model'],
  58. 'images' => $params['images'],
  59. 'cate_id' => ','.$params['cate_id'].',',
  60. 'area_id' => ','.$params['area_id'].',',
  61. 'money' => $params['money'],
  62. 'content'=>$params['content'],
  63. 'order_id'=>0,
  64. ]);
  65. if($result){
  66. $service_fee = ServiceCharge::find(1);
  67. $order_money = 0;
  68. switch ($params['type']){
  69. case 1 :
  70. $order_money =$service_fee['agricultural_machinery_service_fee'];
  71. break;
  72. case 2 :
  73. $order_money =$service_fee['bake_service_fee'];
  74. break;
  75. case 3 :
  76. $order_money =$service_fee['air_control_service_fee'];
  77. break;
  78. }
  79. $data = [
  80. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  81. 'user_id' => $params['user_id'],
  82. 'service_id'=>$result['id'],
  83. 'pay_status' => PayEnum::UNPAID,
  84. 'order_amount' => $order_money,
  85. ];
  86. $order = RechargeOrder::create($data);
  87. $user_service_info = UserService::find($result['id']);
  88. $user_service_info->order_id = $order['id'];
  89. $user_service_info->save();
  90. $order_info = [
  91. 'order_id' => (int)$order['id'],
  92. 'order_sn' => $order['sn'],
  93. 'from' => 'service',
  94. 'result'=>$result
  95. ];
  96. }
  97. Db::commit();
  98. return ['code'=>1,'data'=>$order_info];
  99. } catch (\Exception $e) {
  100. Db::rollback();
  101. self::setError($e->getMessage());
  102. return ['code'=>0,'data'=>[]];
  103. }
  104. }
  105. /**
  106. * @notes
  107. * @param $params
  108. * @return array|false
  109. * @author 段誉
  110. * @date 2022/9/6 19:26
  111. */
  112. public static function getInfo($params,$user_id)
  113. {
  114. try {
  115. $where = [];
  116. $where[]=['user_id','=',$user_id];
  117. $where[]=['type','=',$params['type']];
  118. $serviceInfo = UserService::where($where)->append(['type_desc','cate_desc','area_desc','images','user','orderInfo'])->findOrEmpty();
  119. if($serviceInfo->isEmpty()){
  120. $status = -1;
  121. }else{
  122. if($serviceInfo['status'] == 0){
  123. $status = 0;
  124. }else if($serviceInfo['status'] == 2){
  125. $status = 2;
  126. }else{
  127. $status = 1;
  128. }
  129. }
  130. return [
  131. 'status' => $status,
  132. 'info' => $serviceInfo,
  133. ];
  134. } catch (\Exception $e) {
  135. self::setError($e->getMessage());
  136. return false;
  137. }
  138. }
  139. /**
  140. * @notes 地址列表
  141. * @author 段誉
  142. * @date 2022/9/16 17:56
  143. */
  144. public static function getsAreaLists($get)
  145. {
  146. $where=[];
  147. $where[]=['status','=',1];
  148. if(isset($get['title'])){
  149. $where[]=['title','like','%'.$get['title'].'%'];
  150. }
  151. $area_list = AssetArea::where($where)->field('id,title')->order('sort desc,id asc')->select()->toArray();
  152. return $area_list;
  153. }
  154. /**
  155. * @notes 地址列表
  156. * @author 段誉
  157. * @date 2022/9/16 17:56
  158. */
  159. public static function getsCateLists($get)
  160. {
  161. $where=[];
  162. $where[]=['type','=',$get['type']];
  163. $where[]=['status','=',1];
  164. if(isset($get['name'])){
  165. $where[]=['name','like','%'.$get['name'].'%'];
  166. }
  167. $cate_list = ServiceCategory::where($where)->field('id,name')->order('sort desc,id asc')->select()->toArray();
  168. return $cate_list;
  169. }
  170. /**
  171. * @notes 续费订单
  172. * @param array $params
  173. * @return bool
  174. * @author 段誉
  175. * @date 2022/9/7 15:37
  176. */
  177. public static function Renew(array $params)
  178. {
  179. Db::startTrans();
  180. try {
  181. $where['user_id'] = $params['user_id'];
  182. $where['type'] = $params['type'];
  183. $info = UserService::where($where)->findOrEmpty();
  184. $order_info = [];
  185. if($info){
  186. if($info['expiration_time'] > time()){
  187. Db::rollback();
  188. self::setError('服务未到期,无需进行续费操作');
  189. return ['code'=>0,'data'=>[]];
  190. }
  191. $service_fee = ServiceCharge::find(1);
  192. $order_money = 0;
  193. switch ($params['type']){
  194. case 1 :
  195. $order_money =$service_fee['agricultural_machinery_service_fee'];
  196. break;
  197. case 2 :
  198. $order_money =$service_fee['bake_service_fee'];
  199. break;
  200. case 3 :
  201. $order_money =$service_fee['air_control_service_fee'];
  202. break;
  203. }
  204. $data = [
  205. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  206. 'user_id' => $params['user_id'],
  207. 'service_id'=>$info['id'],
  208. 'pay_status' => PayEnum::UNPAID,
  209. 'order_amount' => $order_money,
  210. ];
  211. $order = RechargeOrder::create($data);
  212. $info->order_id = $order['id'];
  213. $info->status = 0;
  214. $info->save();
  215. $order_info = [
  216. 'order_id' => (int)$order['id'],
  217. 'order_sn' => $order['sn'],
  218. 'from' => 'service',
  219. ];
  220. }
  221. Db::commit();
  222. return ['code'=>1,'data'=>$order_info];
  223. } catch (\Exception $e) {
  224. Db::rollback();
  225. self::setError($e->getMessage());
  226. return ['code'=>0,'data'=>[]];
  227. }
  228. }
  229. public static function updateServiceStatus(){
  230. $where = [];
  231. $where[]=['status','=' ,1];
  232. $where[]=['is_auto_upd','=', 0];
  233. $where[]=['expiration_time','<', time()];
  234. $list = UserService::where($where)->select()->toArray();
  235. $remark = '';
  236. foreach($list as $k=>$v){
  237. $updatewhere['id'] = $v['id'];
  238. $updateData['status'] = 2;
  239. $updateData['is_auto_upd'] = 1;
  240. UserService::where($updatewhere)->update($updateData);
  241. $remark .='id='.$v['id'].'~已到期,状态更新~';
  242. }
  243. if(empty($remark)){
  244. $remark = '无更新数据';
  245. }
  246. return $remark;
  247. }
  248. }