PropertyHeadLogic.php 6.4 KB

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