UserService.php 8.9 KB

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