|
@@ -7,7 +7,9 @@ use app\common\library\Ems;
|
|
|
use app\common\library\Sms;
|
|
|
use fast\Random;
|
|
|
use think\Config;
|
|
|
+use think\Exception;
|
|
|
use think\Validate;
|
|
|
+use think\Db;
|
|
|
|
|
|
/**
|
|
|
* 会员接口
|
|
@@ -345,4 +347,281 @@ class User extends Api
|
|
|
$this->error($this->auth->getError());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户申请提现
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function userwithdraw(){
|
|
|
+ try {
|
|
|
+ $usrr_model = new \app\common\model\User();
|
|
|
+
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+
|
|
|
+ $params = $this->request->param();
|
|
|
+
|
|
|
+ $money = isset($params['money'])?$params['money']:0;
|
|
|
+ if(!is_numeric($money) || $money <= 0){
|
|
|
+ $this->error("非法金额");
|
|
|
+ }
|
|
|
+ $user_money = $usrr_model->where("id",$user_id)->value("money");
|
|
|
+ if($money > $user_money){
|
|
|
+ $this->error("可提现余额不足");
|
|
|
+ }
|
|
|
+ $out_trade_no = $params['out_trade_no'];
|
|
|
+
|
|
|
+ //插入提现表
|
|
|
+ $add = $usrr_model->add($user_id,$money,$out_trade_no);
|
|
|
+
|
|
|
+ if($add){
|
|
|
+ $this->success("提现申请成功");
|
|
|
+ }else{
|
|
|
+ $this->error("提现申请失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception $e){
|
|
|
+
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取我的积分和邀请列表 --待定
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function getUserScoreList(){
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+ $usrr_model = new \app\common\model\User();
|
|
|
+ $score = $usrr_model->where('id',$user_id)->value("score");
|
|
|
+
|
|
|
+ $list = Db::name("hu_points_log")->where("user_id",$user_id)->whereNull("deletetime")->order('id desc')->select();
|
|
|
+ $data = [
|
|
|
+ 'list'=>$list,
|
|
|
+ 'score'=>$score,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->success("我的积分",$data);
|
|
|
+
|
|
|
+ } catch (Exception $e){
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户邀请列表和邀请码 --待定
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function getUserInviteList(){
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+
|
|
|
+ //判断有无邀请码
|
|
|
+ $usrr_model = new \app\common\model\User();
|
|
|
+ $code = $usrr_model->where('id',$user_id)->value("code");
|
|
|
+ if(empty($code)){
|
|
|
+ //生成邀请码
|
|
|
+ $code = generateUniqueInvitationCode(6);
|
|
|
+ $usrr_model->where('id',$user_id)->update(['code'=>$code]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //我邀请的人
|
|
|
+ $list = Db::name("hu_user_invite")->alias('i')->join('fa_user u','i.user_id=u.id')->field("nickname,avatar,i.createtime")->where("invite_id",$user_id)->where("i.status",'1')->whereNull("i.deletetime")->select();
|
|
|
+
|
|
|
+ if(!empty($list)){
|
|
|
+
|
|
|
+ foreach ($list as $key=>$value){
|
|
|
+ $list[$key]['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
|
|
+ //奖励积分
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'code'=>$code,
|
|
|
+ 'list'=>$list
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->success("邀请码和邀请的人",$data);
|
|
|
+
|
|
|
+ } catch (Exception $e){
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的收藏列表
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function getUsetLoveList(){
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+
|
|
|
+ $list = Db::name("unishop_favorite")->where("user_id",$user_id)->order('id desc')->select();
|
|
|
+
|
|
|
+ if(!empty($list)){
|
|
|
+ foreach ($list as $key=>$value){
|
|
|
+ $goods = json_decode($value['snapshot'],true);
|
|
|
+ $list[$key]['id'] = $goods['id'];
|
|
|
+ $list[$key]['image'] = $goods['image'];
|
|
|
+ $list[$key]['title'] = $goods['title'];
|
|
|
+ $list[$key]['sales_price'] = $goods['sales_price'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success("收藏列表",$list);
|
|
|
+
|
|
|
+ } catch (Exception $e){
|
|
|
+
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品收藏添加|取消
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function userLove(){
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+
|
|
|
+ $gid = input("gid",'0');
|
|
|
+ $goods = Db::name("unishop_product")->where("id",$gid)->whereNull("deletetime")->find();
|
|
|
+ if(empty($goods)){
|
|
|
+ $this->error("商品不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ $love = Db::name("unishop_favorite")->where("user_id",$user_id)->where("product_id",$goods['id'])->find();
|
|
|
+
|
|
|
+ if(!empty($love)){
|
|
|
+
|
|
|
+ $del = Db::name("unishop_favorite")->where("user_id",$user_id)->where("product_id",$goods['id'])->delete();
|
|
|
+ if($del){
|
|
|
+ $this->success("取消收藏成功");
|
|
|
+ }else{
|
|
|
+ $this->error("取消收藏失败");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+
|
|
|
+ $data['user_id'] = $user_id;
|
|
|
+ $data['product_id'] = $goods['id'];
|
|
|
+ $data['snapshot'] = json_encode($goods,JSON_UNESCAPED_UNICODE);
|
|
|
+ $data['createtime'] = time();
|
|
|
+
|
|
|
+ $add = Db::name("unishop_favorite")->insert($data);
|
|
|
+
|
|
|
+ if($add){
|
|
|
+ $this->success("收藏成功");
|
|
|
+ }else{
|
|
|
+ $this->error("收藏失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception $e){
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的地址管理
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function getAddressList(){
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+
|
|
|
+ $list = Db::name("unishop_address")->where("user_id",$user_id)->order("is_default desc,id desc")->select();
|
|
|
+
|
|
|
+ if(!empty($list)){
|
|
|
+ foreach ($list as $key=>$value){
|
|
|
+
|
|
|
+ $list[$key]['province'] = Db::name("unishop_area")->where("id",$value['province_id'])->value("name");
|
|
|
+ $list[$key]['city'] = Db::name("unishop_area")->where("id",$value['city_id'])->value("name");
|
|
|
+ $list[$key]['area'] = Db::name("unishop_area")->where("id",$value['area_id'])->value("name");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success("地址列表",$list);
|
|
|
+ } catch (Exception $e){
|
|
|
+
|
|
|
+ $this->error($e->getMessage());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 地址新增
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function userAddressAdd(){
|
|
|
+
|
|
|
+ try {
|
|
|
+ $user_id = $this->auth->id;
|
|
|
+ $name = input('name','');
|
|
|
+ $mobile = input('mobile','');
|
|
|
+ $address = input('address','');
|
|
|
+ $province_id = input('province_id','');
|
|
|
+ $city_id = input('city_id','');
|
|
|
+ $area_id = input('area_id','');
|
|
|
+
|
|
|
+ if(empty($name)){
|
|
|
+ $this->error("请填写收件人姓名");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!preg_match('/^1[3456789]\d{9}$/', $mobile)) {
|
|
|
+ $this->error("手机号码格式正确");;
|
|
|
+ }
|
|
|
+ if(empty($address)){
|
|
|
+ $this->error("请填写具体收件地址");
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['user_id'] = $user_id;
|
|
|
+ $data['name'] = $name;
|
|
|
+ $data['mobile'] = $mobile;
|
|
|
+ $data['address'] = $address;
|
|
|
+ $data['province_id'] = $province_id;
|
|
|
+ $data['city_id'] = $city_id;
|
|
|
+ $data['area_id'] = $area_id;
|
|
|
+ $data['createtime'] = time();
|
|
|
+ $data['updatetime'] = time();
|
|
|
+
|
|
|
+ $add = Db::name("unishop_address")->insert($data);
|
|
|
+ if($add){
|
|
|
+ $this->success("添加成功");
|
|
|
+ }else{
|
|
|
+ $this->error("添加失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception $e){
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|