PropertyHeadLogic.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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\property;
  15. use app\adminapi\logic\user\UserLogic;
  16. use app\common\model\property\PropertyHead;
  17. use app\common\logic\BaseLogic;
  18. use app\common\model\user\User;
  19. use app\common\service\wechat\WeChatMnpService;
  20. use Exception;
  21. use think\facade\Db;
  22. use think\facade\Log;
  23. /**
  24. * PropertyHead逻辑
  25. * Class PropertyHeadLogic
  26. * @package app\adminapi\logic
  27. */
  28. class PropertyHeadLogic extends BaseLogic
  29. {
  30. /**
  31. * @notes 添加
  32. * @param array $params
  33. * @return bool
  34. * @author likeadmin
  35. * @date 2024/09/19 10:48
  36. */
  37. public static function add(array $params): bool
  38. {
  39. Db::startTrans();
  40. try {
  41. $info = PropertyHead::where('head_mobile',$params['head_mobile'])->findOrEmpty();
  42. if(!$info->isEmpty()){
  43. throw new \Exception('该手机号已入驻代理');
  44. }
  45. PropertyHead::create([
  46. 'property_name' => $params['property_name'],
  47. 'village_name' => $params['village_name'],
  48. 'address' => $params['address'],
  49. 'head_name' => $params['head_name'],
  50. 'head_mobile' => $params['head_mobile'],
  51. 'ratio' => $params['ratio']??0,
  52. 'type' => isset($params['type']) ? $params['type'] : 1,
  53. 'head_bank_card' => $params['head_bank_card']??'',
  54. 'head_corporate_bank' => $params['head_corporate_bank']??'',
  55. 'lon' => $params['lon']??0,
  56. 'lat' => $params['lat']??0,
  57. 'remark' => $params['remark']??'',
  58. 'bind_date'=>!empty($params['bind_date'])?$params['bind_date']:0,
  59. 'sale_type'=>$params['sale_type']??0,
  60. 'sale_id'=>$params['sale_id']??0,
  61. 'is_cooperate'=>$params['is_cooperate']??1,
  62. 'province' => $params['province']??0,
  63. 'city' => $params['city']??0,
  64. 'area_name' => $params['area_name']??'',
  65. 'door_images' => $params['door_images']??'',
  66. 'openid' => $params['openid']??'',
  67. 'corporate_bank_name' => $params['corporate_bank_name']??'',
  68. 'scale_images' => $params['scale_images']??'',
  69. 'rating_value' => $params['rating_value']??0,
  70. ]);
  71. Db::commit();
  72. return true;
  73. } catch (\Exception $e) {
  74. Db::rollback();
  75. self::setError($e->getMessage());
  76. return false;
  77. }
  78. }
  79. /**
  80. * @notes 编辑
  81. * @param array $params
  82. * @return bool
  83. * @author likeadmin
  84. * @date 2024/09/19 10:48
  85. */
  86. public static function edit(array $params): bool
  87. {
  88. $headMobile = PropertyHead::where('id', $params['id'])->value('head_mobile');
  89. Db::startTrans();
  90. try {
  91. // 手机号不同时做判断
  92. if($headMobile != $params['head_mobile']){
  93. $user = User::where(['mobile' => $params['head_mobile']])->findOrEmpty();
  94. if (!$user->isEmpty()) {
  95. throw new \Exception('该手机号已被注册');
  96. }
  97. // 更换用户手机号 account
  98. User::where(['mobile' => $headMobile])->save(['mobile' => $params['head_mobile']]);
  99. }
  100. PropertyHead::where('id', $params['id'])->update([
  101. 'property_name' => $params['property_name'],
  102. 'village_name' => $params['village_name'],
  103. 'address' => $params['address'],
  104. 'head_name' => $params['head_name'],
  105. 'head_mobile' => $params['head_mobile'],
  106. 'ratio' => $params['ratio'],
  107. 'type' => isset($params['type']) ? $params['type'] : 1,
  108. 'head_bank_card' => $params['head_bank_card'],
  109. 'head_corporate_bank' => $params['head_corporate_bank']??'',
  110. 'lon' => $params['lon'],
  111. 'lat' => $params['lat'],
  112. 'remark' => $params['remark'],
  113. 'bind_date'=>!empty($params['bind_date'])?$params['bind_date']:0,
  114. 'sale_type'=>$params['sale_type']??0,
  115. 'sale_id'=>$params['sale_id']??0,
  116. 'is_cooperate'=>$params['is_cooperate']??1,
  117. 'province' => $params['province']??0,
  118. 'city' => $params['city']??0,
  119. 'area_name' => $params['area_name']??'',
  120. 'door_images' => $params['door_images']??'',
  121. 'openid' => $params['openid']??'',
  122. 'corporate_bank_name' => $params['corporate_bank_name']??'',
  123. 'scale_images' => $params['scale_images']??'',
  124. 'rating_value' => $params['rating_value']??0,
  125. ]);
  126. Db::commit();
  127. return true;
  128. } catch (\Exception $e) {
  129. Db::rollback();
  130. self::setError($e->getMessage());
  131. return false;
  132. }
  133. }
  134. /**
  135. * @notes 删除
  136. * @param array $params
  137. * @return bool
  138. * @author likeadmin
  139. * @date 2024/09/19 10:48
  140. */
  141. public static function delete(array $params): bool
  142. {
  143. return PropertyHead::destroy($params['id']);
  144. }
  145. /**
  146. * @notes 获取详情
  147. * @param $params
  148. * @return array
  149. * @author likeadmin
  150. * @date 2024/09/19 10:48
  151. */
  152. public static function detail($params): array
  153. {
  154. return PropertyHead::findOrEmpty($params['id'])->toArray();
  155. }
  156. public static function updateUserId(string $head_mobile,int $userId): bool
  157. {
  158. Db::startTrans();
  159. try {
  160. PropertyHead::where('head_mobile', $head_mobile)->update(['user_id' => $userId]);
  161. Db::commit();
  162. return true;
  163. } catch (\Exception $e) {
  164. Db::rollback();
  165. self::setError($e->getMessage());
  166. return false;
  167. }
  168. }
  169. public static function selectList(): array
  170. {
  171. return PropertyHead::where('id','>',0)->select()->toArray();
  172. }
  173. /**
  174. * @param $params
  175. * @param $url
  176. * @return string
  177. */
  178. public static function getWechatQrcode($params,$url)
  179. {
  180. try {
  181. $mnp_page = 'pages/tabView/main';
  182. $response = (new WeChatMnpService())->getUnlimitedQRCode(
  183. 'property_head_id='.$params['id'],
  184. $mnp_page,
  185. env('miniprogram.mini_env_version', 'release'),
  186. false
  187. );
  188. $qrcode = $response->getContent();
  189. if(!is_dir('./uploads/wx_qrcode/'.date('Ymd'))){
  190. mkdir('./uploads/wx_qrcode/'.date('Ymd'));
  191. }
  192. $file_name = 'uploads/wx_qrcode/'.date('Ymd').'/'.time().rand(1000,9999).'.png';
  193. file_put_contents($file_name, $qrcode);
  194. return 'data:png;base64,' . base64_encode(file_get_contents($file_name));
  195. } catch (\Throwable $e) {
  196. Log::info('getQRCode:'.$e->getMessage());
  197. return '';
  198. }
  199. }
  200. }