ServiceLogic.php 11 KB

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