UserService.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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\common\model\agricultural_machinery;
  15. use app\common\model\agricultural_machinery\ServiceCategory;
  16. use app\common\model\BaseModel;
  17. use app\common\model\asset\AssetArea;
  18. use app\common\model\recharge\RechargeOrder;
  19. use app\common\service\FileService;
  20. use app\common\model\user\User;
  21. use think\model\concern\SoftDelete;
  22. /**
  23. * 服务管理模型
  24. * Class ArticleCate
  25. * @package app\common\model\article;
  26. */
  27. class UserService extends BaseModel
  28. {
  29. use SoftDelete;
  30. protected $deleteTime = 'delete_time';
  31. /**
  32. * @notes 关联用户
  33. * @return \think\model\relation\HasMany
  34. * @author 段誉
  35. * @date 2022/10/19 16:59
  36. */
  37. public function user()
  38. {
  39. return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar');
  40. }
  41. public function orderInfo()
  42. {
  43. return $this->hasOne(RechargeOrder::class, 'id', 'order_id');
  44. }
  45. /**
  46. * @notes 状态描述
  47. * @param $value
  48. * @param $data
  49. * @return string
  50. * @author 段誉 状态 0 新增 1 有效 2 已过期
  51. * @date 2022/9/15 11:25
  52. */
  53. public function getStatusDescAttr($value, $data)
  54. {
  55. $status = $data['status'];
  56. $desc = [
  57. 0 => '新增',
  58. 1 => '已支付',
  59. 2 => '已过期',
  60. ];
  61. return $desc[$status] ?? '';
  62. }
  63. public function getPayStatusDescAttr($value, $data)
  64. {
  65. $status = $data['pay_status'];
  66. $desc = [
  67. 0 => '未支付',
  68. 1 => '已支付',
  69. ];
  70. return $desc[$status] ?? '';
  71. }
  72. /**
  73. * @notes
  74. * @param $value
  75. * @param $data
  76. * @return int
  77. * @author 段誉
  78. * @date 2022/9/15 11:32
  79. */
  80. public function getPayInfoAttr($value, $data)
  81. {
  82. $where['user_id'] = $data['user_id'];
  83. $rechare_order = RechargeOrder::where($where)->order('id desc')->find();
  84. return $rechare_order;
  85. }
  86. public function getTypeDescAttr($value,$data){
  87. $type = $data['type'];
  88. $desc = [
  89. 1 => '农机手',
  90. 2 => '烘干服务',
  91. 3 => '飞防服务',
  92. ];
  93. return $desc[$type] ?? '';
  94. }
  95. public function getCateDescAttr($value,$data){
  96. $cate_id_arr = explode(',',$data['cate_id']);
  97. $cate_id_arr = array_filter($cate_id_arr);
  98. $cateWhere = [];
  99. $cateWhere[]=['id','in',$cate_id_arr];
  100. $cate_list = ServiceCategory::where($cateWhere)->field('id,name')->select()->toArray();
  101. $cate_arr = array_column($cate_list,'name');
  102. $cate_str = implode(',',$cate_arr);
  103. return['cate_str'=>$cate_str,'cate_arr'=>$cate_list];
  104. }
  105. public function getAreaDescAttr($value,$data){
  106. $area_id_arr = explode(',',$data['area_id']);
  107. $area_id_arr = array_filter($area_id_arr);
  108. $aresWhere = [];
  109. $aresWhere[]=['id','in',$area_id_arr];
  110. $area_list = AssetArea::where($aresWhere)->field('id,title')->select()->toArray();
  111. $area_arr = array_column($area_list,'title');
  112. $area_str = implode(',',$area_arr);
  113. return['area_str'=>$area_str,'area_arr'=>$area_list];
  114. }
  115. /**
  116. * @notes 设置图片域名
  117. * @param $value
  118. * @param $data
  119. * @return array|string|string[]|null
  120. * @author 段誉
  121. * @date 2022/9/28 10:17
  122. */
  123. public function getContentAttr($value, $data)
  124. {
  125. return get_file_domain($value);
  126. }
  127. /**
  128. * @notes 清除图片域名
  129. * @param $value
  130. * @param $data
  131. * @return array|string|string[]
  132. * @author 段誉
  133. * @date 2022/9/28 10:17
  134. */
  135. public function setContentAttr($value, $data)
  136. {
  137. return clear_file_domain($value);
  138. }
  139. /**
  140. * @notes 清除图片域名
  141. * @param $value
  142. * @param $data
  143. * @return array|string|string[]
  144. * @author 段誉
  145. * @date 2022/9/28 10:17
  146. */
  147. // public function setImagesAttr($value,$data)
  148. // {
  149. // $imagesArr = explode(',',$data['images']);
  150. // $imagesStr = '';
  151. // foreach($imagesArr as $k=>$v){
  152. // if($k==0){
  153. // $imagesStr = clear_file_domain($v);
  154. // }else{
  155. // $imagesStr .=','. clear_file_domain($v);
  156. // }
  157. //
  158. // }
  159. // return $imagesStr;
  160. // }
  161. // public function setDriverImageAttr($value,$data)
  162. // {
  163. // return $imagesStr = clear_file_domain($data['driver_image']);
  164. // $imagesArr = explode(',',$data['driver_image']);
  165. // $imagesStr = '';
  166. // foreach($imagesArr as $k=>$v){
  167. // if($k==0){
  168. // $imagesStr = clear_file_domain($v);
  169. // }else{
  170. // $imagesStr .=','. clear_file_domain($v);
  171. // }
  172. //
  173. // }
  174. // return $imagesStr;
  175. // }
  176. // public function setDrivingImageAttr($value,$data)
  177. // {
  178. // $imagesArr = explode(',',$data['driving_image']);
  179. // $imagesStr = '';
  180. // foreach($imagesArr as $k=>$v){
  181. // if($k==0){
  182. // $imagesStr = clear_file_domain($v);
  183. // }else{
  184. // $imagesStr .=','. clear_file_domain($v);
  185. // }
  186. //
  187. // }
  188. //
  189. // return $imagesStr;
  190. // }
  191. // public function setAgriculturalImageAttr($value,$data)
  192. // {
  193. // $imagesArr = explode(',',$data['agricultural_image']);
  194. // $imagesStr = '';
  195. // foreach($imagesArr as $k=>$v){
  196. // if($k==0){
  197. // $imagesStr = clear_file_domain($v);
  198. // }else{
  199. // $imagesStr .=','. clear_file_domain($v);
  200. // }
  201. //
  202. // }
  203. // return $imagesStr;
  204. // }
  205. /**
  206. * @notes 加图片域名
  207. * @param $value
  208. * @param $data
  209. * @return array|string|string[]
  210. * @author 段誉
  211. * @date 2022/9/28 10:17
  212. */
  213. public function getImagesAttr($value,$data)
  214. {
  215. $imagesArr = explode(',',$data['images']);
  216. $imagesStr = '';
  217. foreach($imagesArr as $k=>$v){
  218. if($k==0){
  219. $imagesStr = FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  220. }else{
  221. $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  222. }
  223. }
  224. return $imagesStr;
  225. }
  226. public function getDriverImageAttr($value,$data)
  227. {
  228. $imagesArr = explode(',',$data['driver_image']);
  229. $imagesStr = '';
  230. foreach($imagesArr as $k=>$v){
  231. if($k==0){
  232. $imagesStr = FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  233. }else{
  234. $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  235. }
  236. }
  237. return $imagesStr;
  238. }
  239. public function getDrivingImageAttr($value,$data)
  240. {
  241. $imagesArr = explode(',',$data['driving_image']);
  242. $imagesStr = '';
  243. foreach($imagesArr as $k=>$v){
  244. if($k==0){
  245. $imagesStr = FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  246. }else{
  247. $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  248. }
  249. }
  250. return $imagesStr;
  251. }
  252. public function getAgriculturalImageAttr($value,$data)
  253. {
  254. $imagesArr = explode(',',$data['agricultural_image']);
  255. $imagesStr = '';
  256. foreach($imagesArr as $k=>$v){
  257. if($k==0){
  258. $imagesStr = FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  259. }else{
  260. $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
  261. }
  262. }
  263. return $imagesStr;
  264. }
  265. }