UserServiceLogic.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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\adminapi\logic\agricultural_machinery;
  15. use app\common\enum\PayEnum;
  16. use app\common\enum\YesNoEnum;
  17. use app\common\logic\BaseLogic;
  18. use app\common\model\agricultural_machinery\UserService;
  19. use app\common\model\article\ArticleCate;
  20. use app\common\model\user\User;
  21. use app\common\model\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
  22. use app\common\model\recharge\RechargeOrder;
  23. use app\common\model\ServiceCharge;
  24. use think\facade\Db;
  25. /**
  26. * 服务管理逻辑
  27. * Class ArticleCateLogic
  28. * @package app\adminapi\logic\article
  29. */
  30. class UserServiceLogic extends BaseLogic
  31. {
  32. /**
  33. * @notes 添加农耕分类
  34. * @param array $params
  35. * @author heshihu
  36. * @date 2022/2/18 10:17
  37. */
  38. public static function add(array $params,$type_name)
  39. {
  40. Db::startTrans();
  41. try {
  42. $where['user_id'] = $params['user_id'];
  43. $where['type'] = $params['type'];
  44. $userService = UserService::where($where)->findOrEmpty();
  45. if(!$userService->isEmpty()){
  46. Db::rollback();
  47. self::setError('当前用户存在'.$type_name.'服务信息,无需添加');
  48. return ['code'=>0,'data'=>[]];
  49. }
  50. $result = UserService::create([
  51. 'user_id' => $params['user_id'],
  52. 'type' => $params['type'] ?? 1,
  53. 'name' => $params['name'],
  54. 'mobile' => $params['mobile'],
  55. 'agricultural_machinery_model' =>$params['agricultural_machinery_model'],
  56. 'images' => $params['images'],
  57. 'cate_id' => ','.$params['cate_id'].',',
  58. 'area_id' => ','.$params['area_id'].',',
  59. 'money' => $params['money'],
  60. 'content'=>$params['content'],
  61. 'order_id'=>0,
  62. ]);
  63. if($result){
  64. $service_fee = ServiceCharge::find(1);
  65. $order_money = 0;
  66. switch ($params['type']){
  67. case 1 :
  68. $order_money =$service_fee['agricultural_machinery_service_fee'];
  69. break;
  70. case 2 :
  71. $order_money =$service_fee['bake_service_fee'];
  72. break;
  73. case 3 :
  74. $order_money =$service_fee['air_control_service_fee'];
  75. break;
  76. }
  77. $data = [
  78. 'sn' => generate_sn(RechargeOrder::class, 'sn'),
  79. 'user_id' => $params['user_id'],
  80. 'pay_way'=> 4,
  81. 'pay_time'=>time(),
  82. 'service_id'=>$result['id'],
  83. 'pay_status' => PayEnum::ISPAID,
  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->status = 1;
  90. $user_service_info->expiration_time = time()+365*24*60*60;
  91. $user_service_info->save();
  92. $order_info = [
  93. 'order_id' => (int)$order['id'],
  94. 'order_sn' => $order['sn'],
  95. 'from' => 'service',
  96. 'result'=>$result
  97. ];
  98. }
  99. Db::commit();
  100. return ['code'=>1,'data'=>$order_info];
  101. } catch (\Exception $e) {
  102. Db::rollback();
  103. self::setError($e->getMessage());
  104. return ['code'=>0,'data'=>[]];
  105. }
  106. }
  107. /**
  108. * @notes 删除农耕分类
  109. * @param array $params
  110. * @author heshihu
  111. * @date 2022/2/21 17:52
  112. */
  113. public static function delete(array $params)
  114. {
  115. UserService::destroy($params['id']);
  116. }
  117. /**
  118. * @notes 查看服务商详情
  119. * @param $params
  120. * @return array
  121. * @author heshihu
  122. * @date 2022/2/21 17:54
  123. */
  124. public static function detail($params) : array
  125. {
  126. return UserService::findOrEmpty($params['id'])->toArray();
  127. }
  128. /**
  129. * @notes 更改服务商状态
  130. * @param array $params
  131. * @return bool
  132. * @author heshihu
  133. * @date 2022/2/21 18:04
  134. */
  135. public static function updateStatus(array $params)
  136. {
  137. UserService::update([
  138. 'id' => $params['id'],
  139. 'status' => $params['status']
  140. ]);
  141. return true;
  142. }
  143. /**
  144. * @notes 有效用户数据
  145. * @return array
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\DbException
  148. * @throws \think\db\exception\ModelNotFoundException
  149. * @author 段誉
  150. * @date 2022/10/13 10:53
  151. */
  152. public static function getValidUserData()
  153. {
  154. $list = User::where(['is_disable' => YesNoEnum::NO])
  155. ->field('id,sn,nickname,account')
  156. ->order([ 'id' => 'desc'])
  157. ->select()
  158. ->toArray();
  159. return $list;
  160. }
  161. public static function getServiceContent(){
  162. $info = ServiceCharge::field('agricultural_service,bake_service,air_service')->find(1)->toArray();
  163. return $info;
  164. }
  165. public static function saveServiceContent($post){
  166. if(isset($post['agricultural_service']) && !empty($post['agricultural_service'])){
  167. $saveData['agricultural_service'] = $post['agricultural_service'];
  168. }
  169. if(isset($post['bake_service']) && !empty($post['bake_service'])){
  170. $saveData['bake_service'] = $post['bake_service'];
  171. }
  172. if(isset($post['air_service']) && !empty($post['air_service'])){
  173. $saveData['air_service'] = $post['air_service'];
  174. }
  175. $saveData['id'] = 1;
  176. ServiceCharge::update($saveData);
  177. return true;
  178. }
  179. }