User.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php namespace Pinterface\Api;
  2. use Dever;
  3. use Pinterface\Lib\Core;
  4. use Pact\Lib\Core as Act;
  5. class User extends Core
  6. {
  7. protected $login = true;
  8. protected $entry = true;
  9. # 我的信息
  10. public function info()
  11. {
  12. $data['user'] = $this->place->user;
  13. $data['user']['mobile'] = \Dever\Helper\Str::hide($this->place->user['mobile']);
  14. if ($data['user']['type'] == 2) {
  15. $data['user']['mobile'] = '临时用户,请先绑定手机号';
  16. }
  17. # 优惠券
  18. $data['user']['coupon'] = Dever::db('puser/coupon')->count(['uid' => $this->place->uid, 'status' => 1]);
  19. # 礼品卡
  20. $data['user']['gift'] = Dever::db('puser/gift')->count(['uid' => $this->place->uid, 'status' => 1]);
  21. # 权益包
  22. $data['user']['perk'] = Dever::db('puser/perk')->count(['uid' => $this->place->uid, 'status' => 1]);
  23. $data['role'] = [];
  24. $role = Dever::db('prole/info')->select(['status' => 1], ['col' => 'id,name,info']);
  25. # 获取用户的身份
  26. $user_role = Dever::load(\Prole\Lib\User::class)->getList($this->place->uid);
  27. $data['role_info'] = [];
  28. if ($role) {
  29. foreach ($role as $v) {
  30. $level = Dever::db('prole/level')->find(['info_id' => $v['id']]);
  31. if (!$level) {
  32. continue;
  33. }
  34. if (isset($user_role[$v['id']])) {
  35. $v['subname'] = $user_role[$v['id']];
  36. $v['button'] = '了解详情';
  37. } else {
  38. $v['subname'] = '未开通';
  39. $v['button'] = '立即开通';
  40. }
  41. if (!$data['role_info']) {
  42. $data['role_info'] = $v;
  43. }
  44. $data['role'][] = $v;
  45. }
  46. }
  47. # 获取所有积分
  48. $data['score'] = Dever::db('pscore/info')->select(['status' => 1], ['col' => 'id,name']);
  49. # 获取用户的积分
  50. $user_score = Dever::load(\Pscore\Lib\User::class)->getList($this->place->uid);
  51. if ($data['score']) {
  52. foreach ($data['score'] as &$score) {
  53. $score['num'] = $user_score[$score['id']] ?? '0.00';
  54. }
  55. }
  56. # 获取待付款
  57. $data['order_1'] = Dever::db('porder/source')->count(['uid' => $this->place->uid, 'status' => 1]);
  58. # 待发货
  59. $data['order_2'] = Dever::db('porder/source')->count(['uid' => $this->place->uid, 'status' => 2]);
  60. # 待收货
  61. $data['order_3'] = Dever::db('porder/source')->count(['uid' => $this->place->uid, 'status' => ['in', '3,4']]);
  62. # 待评价
  63. $data['order_4'] = Dever::db('porder/source')->count(['uid' => $this->place->uid, 'review_status' => 2]);
  64. # 获取用户管理信息
  65. $data['sales'] = Dever::load(\Psales\Lib\Info::class)->getList($this->place->uid);
  66. return $data;
  67. }
  68. # 仅获取用户信息
  69. public function my()
  70. {
  71. $data['user'] = $this->place->user;
  72. return $data;
  73. }
  74. # 上传图片
  75. public function upload()
  76. {
  77. $file = Dever::input('file', '!empty', '上传文件错误');
  78. $uid = $this->place->uid;
  79. return Dever::load(\Upload\Lib\Save::class)->init(7, 1, false, false)->act($file, 'png', $uid);
  80. }
  81. # 更新我的信息
  82. public function update()
  83. {
  84. $update = [];
  85. $name = Dever::input('name');
  86. if ($name) {
  87. $this->place->user['name'] = $update['name'] = $name;
  88. }
  89. $avatar = Dever::input('avatar');
  90. if ($avatar) {
  91. $this->place->user['avatar'] = $update['avatar'] = $avatar;
  92. }
  93. $sign = Dever::input('sign');
  94. if ($sign) {
  95. $this->place->user['sign'] = $update['sign'] = $sign;
  96. }
  97. $sex = Dever::input('sex');
  98. if ($sex) {
  99. $this->place->user['sex'] = $update['sex'] = $sex;
  100. }
  101. $weixin = Dever::input('weixin');
  102. if ($weixin) {
  103. $this->place->user['weixin'] = $update['weixin'] = $weixin;
  104. }
  105. if ($update) {
  106. Dever::db('puser/info')->update($this->place->uid, $update);
  107. }
  108. return $this->place->user;
  109. }
  110. # 修改密码
  111. public function pwd()
  112. {
  113. # 大于8位字符,至少包含:小写字母、大写字母、数字、特殊字符
  114. //$pwd = Dever::input('pwd', '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$/', '密码');
  115. $pwd = Dever::input('pwd', 'is_string', '密码');
  116. $code = Dever::input('code', 'is_string', '验证码');
  117. Dever::load(\Msg\Lib\Template::class)->check('user_code', $this->place->user['mobile'], $code);
  118. $update = Dever::load(\Manage\Lib\Util::class)->createPwd($pwd);
  119. Dever::db('puser/info')->update($this->place->uid, $update);
  120. }
  121. # 发送短信验证码
  122. public function sms()
  123. {
  124. $data = Dever::load(\Msg\Lib\Template::class)->send('user_code', ['mobile' => $this->place->user['mobile']], [], 'place');
  125. return $data;
  126. }
  127. # 我的分享
  128. public function invite()
  129. {
  130. # 代理邀请码
  131. $data['code'] = Dever::load(\Invite\Lib\Code::class)->get($this->place->uid);
  132. $data['parent'] = 2;
  133. # 获取我的上级
  134. $relation = Dever::load(\Invite\Lib\Relation::class)->getParent($this->place->uid);
  135. if ($relation) {
  136. $data['parent'] = 1;
  137. $data['parent_info'] = Dever::db('puser/info')->find($relation['uid'], ['col' => 'id,name,avatar']);
  138. }
  139. return $data;
  140. }
  141. # 我的下级列表
  142. public function getGroup()
  143. {
  144. $data['parent'] = 2;
  145. # 获取我的上级
  146. $relation = Dever::load(\Invite\Lib\Relation::class)->getParent($this->place->uid);
  147. if ($relation) {
  148. $data['parent'] = 1;
  149. $data['parent_info'] = Dever::db('puser/info')->find($relation['uid'], ['col' => 'id,name,avatar,cdate']);
  150. if ($data['parent_info']) {
  151. $data['parent_info']['cdate_str'] = date('Y-m-d H:i:s', $data['parent_info']['cdate']);
  152. }
  153. }
  154. $relation = Dever::load(\Invite\Lib\Relation::class)->getChild($this->place->uid);
  155. $data['list'] = [];
  156. if ($relation) {
  157. foreach ($relation as $k => $v) {
  158. $data['list'][$k] = Dever::db('puser/info')->find($v['to_uid'], ['col' => 'id,name,avatar,num_order']);
  159. if ($data['list'][$k]) {
  160. $data['list'][$k]['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
  161. # 获取订单数
  162. $data['list'][$k]['order'] = $data['list'][$k]['num_order'] . '单';
  163. }
  164. }
  165. }
  166. $data['page'] = Dever::page('total');
  167. return $data;
  168. }
  169. # 填写邀请码,添加上级
  170. public function addParent()
  171. {
  172. $relation = Dever::load(\Invite\Lib\Relation::class)->getParent($this->place->uid);
  173. if ($relation) {
  174. Dever::error('您已经有上级了');
  175. }
  176. $invite = Dever::input('invite', 'is_numeric', '请填写邀请码');
  177. $parent_uid = Dever::load(\Invite\Lib\Code::class)->getUid($invite);
  178. if (!$parent_uid) {
  179. Dever::error('邀请码不存在');
  180. }
  181. $parent = Dever::db('puser/info')->find($parent_uid);
  182. if (!$parent) {
  183. Dever::error('邀请码不存在');
  184. }
  185. Dever::load(\Invite\Lib\Relation::class)->set($parent_uid, $this->place->uid);
  186. Dever::db('puser/info')->update($this->place->uid, ['parent_uid' => $parent_uid]);
  187. return 'ok';
  188. }
  189. # 获取邀请码
  190. public function code()
  191. {
  192. $account = Dever::input('platform', 'is_string', '账户', 'weixin');
  193. $env = Dever::input('env', 'is_numeric', '运行环境', 3);
  194. $sales_type = Dever::input('sales_type');
  195. $sales_id = Dever::input('sales_id');
  196. $type = Dever::input('type');
  197. if (!$type) {
  198. $type = 0;
  199. }
  200. if (!$sales_type || !$sales_id) {
  201. $sales_type = $this->place->info['sales_type'];
  202. $sales_id = $this->place->info['sales_id'];
  203. }
  204. $result = Dever::load(\Place\Lib\Info::class)->share($this->place->info['id'], $sales_type, $sales_id, $this->place->uid, false, $type);
  205. # 小程序
  206. $data['qrcode'] = $result['applet']['wechat'];
  207. $data['link'] = $result['h5'];
  208. $data['path'] = $result['path'];
  209. return $data;
  210. }
  211. }