PropertyHeadLogic.php 7.0 KB

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