SupplyDemandLogic.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. SupplyDemandInfo::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 detail($params) : array
  51. {
  52. return SupplyDemandInfo::with('area')->findOrEmpty($params['id'])->toArray();
  53. }
  54. /**
  55. * @notes 查看供需详情
  56. * @param $params
  57. * @return array
  58. * @author heshihu
  59. * @date 2022/2/21 17:54
  60. */
  61. public static function detailCate($params) : array
  62. {
  63. return SupplyDemandCate::findOrEmpty($params['id'])->toArray();
  64. }
  65. /**
  66. * @notes 更改服务商状态
  67. * @param array $params
  68. * @return bool
  69. * @author heshihu
  70. * @date 2022/2/21 18:04
  71. */
  72. public static function updateStatus(array $params)
  73. {
  74. SupplyDemandInfo::update([
  75. 'id' => $params['id'],
  76. 'status' => $params['status'],
  77. 'audit_time' =>time(),
  78. 'remark' => $params['remark']
  79. ]);
  80. return true;
  81. }
  82. /**
  83. * @notes 有效用户数据
  84. * @return array
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\DbException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @author 段誉
  89. * @date 2022/10/13 10:53
  90. */
  91. public static function getValidUserData()
  92. {
  93. $list = User::where(['is_disable' => YesNoEnum::NO])
  94. ->field('id,sn,nickname')
  95. ->order([ 'id' => 'desc'])
  96. ->select()
  97. ->toArray();
  98. return $list;
  99. }
  100. /**
  101. * @notes 添加供应分类
  102. * @param array $params
  103. * @author heshihu
  104. * @date 2022/2/18 10:17
  105. */
  106. public static function addCate(array $params)
  107. {
  108. $pid = $params['pid'];
  109. $level = 1;
  110. $pidInfo = SupplyDemandCate::find($pid);
  111. if(!empty($pidInfo)){
  112. $level = $pidInfo['level'] + 1;
  113. }
  114. SupplyDemandCate::create([
  115. 'name' => $params['name'],
  116. 'level' => $level,
  117. 'pid' => $pid,
  118. 'type' => $params['type'] ?? 1,
  119. 'status' => $params['status'] ?? 1,
  120. 'sort' => $params['sort'] ?? 0
  121. ]);
  122. }
  123. public static function editCate(array $params) : bool
  124. {
  125. try {
  126. $pid = $params['pid'];
  127. $level = 1;
  128. $pidInfo = SupplyDemandCate::find($pid);
  129. if(!empty($pidInfo)){
  130. $level = $pidInfo['level'] + 1;
  131. }
  132. SupplyDemandCate::update([
  133. 'id' => $params['id'],
  134. 'name' => $params['name'],
  135. 'level' => $level,
  136. 'pid' => $pid,
  137. 'status' => $params['status'] ?? 1,
  138. 'sort' => $params['sort'] ?? 0
  139. ]);
  140. return true;
  141. } catch (\Exception $e) {
  142. self::setError($e->getMessage());
  143. return false;
  144. }
  145. }
  146. public static function updateCateStatus(array $params)
  147. {
  148. SupplyDemandCate::update([
  149. 'id' => $params['id'],
  150. 'status' => $params['status'],
  151. ]);
  152. return true;
  153. }
  154. public static function deleteCate(array $params)
  155. {
  156. SupplyDemandCate::destroy($params['id']);
  157. }
  158. }