ServiceLogic.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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_type = 0;
  67. $service_fee = ServiceCharge::find(1);
  68. $order_money = 0;
  69. $flag = false ;
  70. switch ($params['type']){
  71. case 1 :
  72. $flag = true ;
  73. $order_money =$service_fee['agricultural_machinery_service_fee'];
  74. break;
  75. case 2 :
  76. $flag = true ;
  77. $order_money =$service_fee['bake_service_fee'];
  78. break;
  79. case 3 :
  80. $flag = true ;
  81. $order_money =$service_fee['air_control_service_fee'];
  82. break;
  83. }
  84. $data = [
  85. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  86. 'user_id' => $params['user_id'],
  87. 'service_id'=>$result['id'],
  88. 'pay_status' => PayEnum::UNPAID,
  89. 'order_amount' => $order_money,
  90. ];
  91. $order = RechargeOrder::create($data);
  92. $user_service_info = UserService::find($result['id']);
  93. $user_service_info->order_id = $order['id'];
  94. $user_service_info->save();
  95. if($flag){
  96. switch ($params['type']){
  97. case 1 :
  98. $updateData['agricultural_id'] =(int)$order['id'];
  99. $updateData['agricultural_status'] =1;
  100. break;
  101. case 2 :
  102. $updateData['bake_id'] =(int)$order['id'];
  103. $updateData['bake_status'] =1;
  104. break;
  105. case 3 :
  106. $updateData['air_id'] =(int)$order['id'];
  107. $updateData['air_status'] =1;
  108. break;
  109. }
  110. $ret = User::where(['id'=> $params['user_id']])->update($updateData);
  111. }
  112. $order_info = [
  113. 'order_id' => (int)$order['id'],
  114. 'order_sn' => $order['sn'],
  115. 'from' => 'service',
  116. 'result'=>$result
  117. ];
  118. }
  119. Db::commit();
  120. return ['code'=>1,'data'=>$order_info];
  121. } catch (\Exception $e) {
  122. Db::rollback();
  123. self::setError($e->getMessage());
  124. return ['code'=>0,'data'=>[]];
  125. }
  126. }
  127. /**
  128. * @notes
  129. * @param $params
  130. * @return array|false
  131. * @author 段誉
  132. * @date 2022/9/6 19:26
  133. */
  134. public static function getInfo($params,$user_id)
  135. {
  136. try {
  137. $where = [];
  138. $where[]=['user_id','=',$user_id];
  139. $where[]=['type','=',$params['type']];
  140. $serviceInfo = UserService::where($where)->append(['type_desc','cate_desc','area_desc','images','user','orderInfo'])->findOrEmpty();
  141. if($serviceInfo->isEmpty()){
  142. $status = -1;
  143. }else{
  144. if($serviceInfo['status'] == 0){
  145. $status = 0;
  146. }else if($serviceInfo['status'] == 2){
  147. $status = 2;
  148. }else{
  149. $status = 1;
  150. }
  151. }
  152. return [
  153. 'status' => $status,
  154. 'info' => $serviceInfo,
  155. ];
  156. } catch (\Exception $e) {
  157. self::setError($e->getMessage());
  158. return false;
  159. }
  160. }
  161. /**
  162. * @notes 地址列表
  163. * @author 段誉
  164. * @date 2022/9/16 17:56
  165. */
  166. public static function getsAreaLists($get)
  167. {
  168. $where=[];
  169. $where[]=['status','=',1];
  170. if(isset($get['title'])){
  171. $where[]=['title','like','%'.$get['title'].'%'];
  172. }
  173. $area_list = AssetArea::where($where)->field('id,title')->order('sort desc,id asc')->select()->toArray();
  174. return $area_list;
  175. }
  176. /**
  177. * @notes 地址列表
  178. * @author 段誉
  179. * @date 2022/9/16 17:56
  180. */
  181. public static function getsCateLists($get)
  182. {
  183. $where=[];
  184. $where[]=['type','=',$get['type']];
  185. $where[]=['status','=',1];
  186. if(isset($get['name'])){
  187. $where[]=['name','like','%'.$get['name'].'%'];
  188. }
  189. $cate_list = ServiceCategory::where($where)->field('id,name')->order('sort desc,id asc')->select()->toArray();
  190. return $cate_list;
  191. }
  192. /**
  193. * @notes 续费订单
  194. * @param array $params
  195. * @return bool
  196. * @author 段誉
  197. * @date 2022/9/7 15:37
  198. */
  199. public static function Renew(array $params)
  200. {
  201. Db::startTrans();
  202. try {
  203. $where['user_id'] = $params['user_id'];
  204. $where['type'] = $params['type'];
  205. $info = UserService::where($where)->findOrEmpty();
  206. $order_info = [];
  207. if($info){
  208. if($info['expiration_time'] > time()){
  209. Db::rollback();
  210. self::setError('服务未到期,无需进行续费操作');
  211. return ['code'=>0,'data'=>[]];
  212. }
  213. $service_fee = ServiceCharge::find(1);
  214. $order_money = 0;
  215. switch ($params['type']){
  216. case 1 :
  217. $order_money =$service_fee['agricultural_machinery_service_fee'];
  218. break;
  219. case 2 :
  220. $order_money =$service_fee['bake_service_fee'];
  221. break;
  222. case 3 :
  223. $order_money =$service_fee['air_control_service_fee'];
  224. break;
  225. }
  226. $data = [
  227. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  228. 'user_id' => $params['user_id'],
  229. 'service_id'=>$info['id'],
  230. 'pay_status' => PayEnum::UNPAID,
  231. 'order_amount' => $order_money,
  232. ];
  233. $order = RechargeOrder::create($data);
  234. $info->order_id = $order['id'];
  235. $info->status = 0;
  236. $info->save();
  237. $order_info = [
  238. 'order_id' => (int)$order['id'],
  239. 'order_sn' => $order['sn'],
  240. 'from' => 'service',
  241. ];
  242. }
  243. Db::commit();
  244. return ['code'=>1,'data'=>$order_info];
  245. } catch (\Exception $e) {
  246. Db::rollback();
  247. self::setError($e->getMessage());
  248. return ['code'=>0,'data'=>[]];
  249. }
  250. }
  251. public static function updateServiceStatus(){
  252. $where = [];
  253. $where[]=['status','=' ,1];
  254. $where[]=['is_auto_upd','=', 0];
  255. $where[]=['expiration_time','<', time()];
  256. $list = UserService::where($where)->select()->toArray();
  257. $remark = '';
  258. foreach($list as $k=>$v){
  259. $updatewhere['id'] = $v['id'];
  260. $updateData['status'] = 2;
  261. $updateData['is_auto_upd'] = 1;
  262. UserService::where($updatewhere)->update($updateData);
  263. $remark .='id='.$v['id'].'~已到期,状态更新~';
  264. }
  265. if(empty($remark)){
  266. $remark = '无更新数据';
  267. }
  268. return $remark;
  269. }
  270. public static function getServiceContentInfo(){
  271. $where['id'] = 1;
  272. $info = ServiceCharge::field('agricultural_service,bake_service,air_service')->find(1)->toArray();
  273. return $info;
  274. }
  275. public static function getUserServiceInfo($user_id){
  276. $info = User::field('id,nickname,mobile,agricultural_status,agricultural_id,bake_status,bake_id,air_status,air_id')
  277. ->find($user_id)->toArray();
  278. return $info;
  279. }
  280. }