PropertyHeadLogic.php 6.7 KB

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