SupplyDemandLogic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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\user\User;
  20. use app\common\model\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
  21. use app\common\model\supply_demand\SupplyDemandInfo;
  22. use app\common\model\supply_demand\SupplyDemandCate;
  23. use app\common\model\recharge\RechargeOrder;
  24. use app\common\model\ServiceCharge;
  25. use think\facade\Db;
  26. /**
  27. * 供需管理逻辑
  28. * Class ArticleCateLogic
  29. * @package app\adminapi\logic\article
  30. */
  31. class SupplyDemandLogic extends BaseLogic
  32. {
  33. /**
  34. * @notes 删除农耕分类
  35. * @param array $params
  36. * @author heshihu
  37. * @date 2022/2/21 17:52
  38. */
  39. public static function delete(array $params)
  40. {
  41. UserService::destroy($params['id']);
  42. }
  43. /**
  44. * @notes 查看供需详情
  45. * @param $params
  46. * @return array
  47. * @author heshihu
  48. * @date 2022/2/21 17:54
  49. */
  50. public static function detailCate($params) : array
  51. {
  52. return SupplyDemandCate::findOrEmpty($params['id'])->toArray();
  53. }
  54. /**
  55. * @notes 更改服务商状态
  56. * @param array $params
  57. * @return bool
  58. * @author heshihu
  59. * @date 2022/2/21 18:04
  60. */
  61. public static function updateStatus(array $params)
  62. {
  63. SupplyDemandInfo::update([
  64. 'id' => $params['id'],
  65. 'status' => $params['status'],
  66. 'audit_time' =>time(),
  67. 'remark' => $params['remark']
  68. ]);
  69. return true;
  70. }
  71. /**
  72. * @notes 有效用户数据
  73. * @return array
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. * @author 段誉
  78. * @date 2022/10/13 10:53
  79. */
  80. public static function getValidUserData()
  81. {
  82. $list = User::where(['is_disable' => YesNoEnum::NO])
  83. ->field('id,sn,nickname')
  84. ->order([ 'id' => 'desc'])
  85. ->select()
  86. ->toArray();
  87. return $list;
  88. }
  89. /**
  90. * @notes 添加供应分类
  91. * @param array $params
  92. * @author heshihu
  93. * @date 2022/2/18 10:17
  94. */
  95. public static function addCate(array $params)
  96. {
  97. $pid = $params['pid'];
  98. $level = 1;
  99. $pidInfo = SupplyDemandCate::find($pid);
  100. if(!empty($pidInfo)){
  101. $level = $pidInfo['level'] + 1;
  102. }
  103. SupplyDemandCate::create([
  104. 'name' => $params['name'],
  105. 'level' => $level,
  106. 'pid' => $pid,
  107. 'type' => $params['type'] ?? 1,
  108. 'status' => $params['status'] ?? 1,
  109. 'sort' => $params['sort'] ?? 0
  110. ]);
  111. }
  112. public static function editCate(array $params) : bool
  113. {
  114. try {
  115. $pid = $params['pid'];
  116. $level = 1;
  117. $pidInfo = SupplyDemandCate::find($pid);
  118. if(!empty($pidInfo)){
  119. $level = $pidInfo['level'] + 1;
  120. }
  121. SupplyDemandCate::update([
  122. 'id' => $params['id'],
  123. 'name' => $params['name'],
  124. 'level' => $level,
  125. 'pid' => $pid,
  126. 'status' => $params['status'] ?? 1,
  127. 'sort' => $params['sort'] ?? 0
  128. ]);
  129. return true;
  130. } catch (\Exception $e) {
  131. self::setError($e->getMessage());
  132. return false;
  133. }
  134. }
  135. public static function updateCateStatus(array $params)
  136. {
  137. SupplyDemandCate::update([
  138. 'id' => $params['id'],
  139. 'status' => $params['status'],
  140. ]);
  141. return true;
  142. }
  143. public static function deleteCate(array $params)
  144. {
  145. SupplyDemandCate::destroy($params['id']);
  146. }
  147. }