ServiceLogic.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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,level,pid,title')->order('sort desc,id asc')->select()->toArray();
  174. if($get['is_tree'] ==1){
  175. $treeList = linear_to_tree($area_list, 'children');
  176. if (empty($treeList) && !empty($area_list)) {
  177. foreach ($area_list as &$v) {
  178. $v['children'] = [];
  179. }
  180. return $area_list;
  181. }
  182. return $treeList;
  183. }else{
  184. return $area_list;
  185. }
  186. }
  187. /**
  188. * @notes 地址列表
  189. * @author 段誉
  190. * @date 2022/9/16 17:56
  191. */
  192. public static function getsCateLists($get)
  193. {
  194. $where=[];
  195. $where[]=['type','=',$get['type']];
  196. $where[]=['status','=',1];
  197. if(isset($get['name'])){
  198. $where[]=['name','like','%'.$get['name'].'%'];
  199. }
  200. $cate_list = ServiceCategory::where($where)->field('id,name')->order('sort desc,id asc')->select()->toArray();
  201. return $cate_list;
  202. }
  203. /**
  204. * @notes 续费订单
  205. * @param array $params
  206. * @return bool
  207. * @author 段誉
  208. * @date 2022/9/7 15:37
  209. */
  210. public static function Renew(array $params)
  211. {
  212. Db::startTrans();
  213. try {
  214. $where['user_id'] = $params['user_id'];
  215. $where['type'] = $params['type'];
  216. $info = UserService::where($where)->findOrEmpty();
  217. $order_info = [];
  218. if($info){
  219. if($info['expiration_time'] > time()){
  220. Db::rollback();
  221. self::setError('服务未到期,无需进行续费操作');
  222. return ['code'=>0,'data'=>[]];
  223. }
  224. $service_fee = ServiceCharge::find(1);
  225. $order_money = 0;
  226. switch ($params['type']){
  227. case 1 :
  228. $order_money =$service_fee['agricultural_machinery_service_fee'];
  229. break;
  230. case 2 :
  231. $order_money =$service_fee['bake_service_fee'];
  232. break;
  233. case 3 :
  234. $order_money =$service_fee['air_control_service_fee'];
  235. break;
  236. }
  237. $data = [
  238. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  239. 'user_id' => $params['user_id'],
  240. 'service_id'=>$info['id'],
  241. 'pay_status' => PayEnum::UNPAID,
  242. 'order_amount' => $order_money,
  243. ];
  244. $order = RechargeOrder::create($data);
  245. $info->order_id = $order['id'];
  246. $info->status = 0;
  247. $info->save();
  248. $order_info = [
  249. 'order_id' => (int)$order['id'],
  250. 'order_sn' => $order['sn'],
  251. 'from' => 'service',
  252. ];
  253. }
  254. Db::commit();
  255. return ['code'=>1,'data'=>$order_info];
  256. } catch (\Exception $e) {
  257. Db::rollback();
  258. self::setError($e->getMessage());
  259. return ['code'=>0,'data'=>[]];
  260. }
  261. }
  262. public static function updateServiceStatus(){
  263. $where = [];
  264. $where[]=['status','=' ,1];
  265. $where[]=['is_auto_upd','=', 0];
  266. $where[]=['expiration_time','<', time()];
  267. $list = UserService::where($where)->select()->toArray();
  268. $remark = '';
  269. foreach($list as $k=>$v){
  270. $updatewhere['id'] = $v['id'];
  271. $updateData['status'] = 2;
  272. $updateData['is_auto_upd'] = 1;
  273. UserService::where($updatewhere)->update($updateData);
  274. $remark .='id='.$v['id'].'~已到期,状态更新~';
  275. }
  276. if(empty($remark)){
  277. $remark = '无更新数据';
  278. }
  279. return $remark;
  280. }
  281. public static function getServiceContentInfo(){
  282. $where['id'] = 1;
  283. $info = ServiceCharge::field('agricultural_service,bake_service,air_service')->find(1)->toArray();
  284. return $info;
  285. }
  286. public static function getUserServiceInfo($user_id){
  287. $info = User::field('id,nickname,mobile,agricultural_status,agricultural_id,bake_status,bake_id,air_status,air_id')
  288. ->find($user_id)->toArray();
  289. return $info;
  290. }
  291. }