UserServiceLogic.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * @return bool
  111. * @author heshihu
  112. * @date 2022/2/21 17:50
  113. */
  114. public static function edit(array $params) : bool
  115. {
  116. try {
  117. AgriculturalMachineryServiceCategory::update([
  118. 'id' => $params['id'],
  119. 'name' => $params['name'],
  120. 'status' => $params['status'] ?? 1,
  121. 'sort' => $params['sort'] ?? 0
  122. ]);
  123. return true;
  124. } catch (\Exception $e) {
  125. self::setError($e->getMessage());
  126. return false;
  127. }
  128. }
  129. /**
  130. * @notes 删除农耕分类
  131. * @param array $params
  132. * @author heshihu
  133. * @date 2022/2/21 17:52
  134. */
  135. public static function delete(array $params)
  136. {
  137. AgriculturalMachineryServiceCategory::destroy($params['id']);
  138. }
  139. /**
  140. * @notes 查看农耕分类详情
  141. * @param $params
  142. * @return array
  143. * @author heshihu
  144. * @date 2022/2/21 17:54
  145. */
  146. public static function detail($params) : array
  147. {
  148. return AgriculturalMachineryServiceCategory::findOrEmpty($params['id'])->toArray();
  149. }
  150. /**
  151. * @notes 更改农耕分类状态
  152. * @param array $params
  153. * @return bool
  154. * @author heshihu
  155. * @date 2022/2/21 18:04
  156. */
  157. public static function updateStatus(array $params)
  158. {
  159. AgriculturalMachineryServiceCategory::update([
  160. 'id' => $params['id'],
  161. 'status' => $params['status']
  162. ]);
  163. return true;
  164. }
  165. /**
  166. * @notes 有效用户数据
  167. * @return array
  168. * @throws \think\db\exception\DataNotFoundException
  169. * @throws \think\db\exception\DbException
  170. * @throws \think\db\exception\ModelNotFoundException
  171. * @author 段誉
  172. * @date 2022/10/13 10:53
  173. */
  174. public static function getValidUserData()
  175. {
  176. $list = User::where(['is_disable' => YesNoEnum::NO])
  177. ->field('id,sn,nickname')
  178. ->order([ 'id' => 'desc'])
  179. ->select()
  180. ->toArray();
  181. return $list;
  182. }
  183. }