PropertyHeadLogic.php 7.5 KB

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