|
@@ -0,0 +1,2189 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | [ WE CAN DO IT MORE SIMPLE ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Copyright (c) 2018-2020 rights reserved.
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Author: TABLE ME
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Date: 2020-08-25 17:23
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+declare (strict_types=1);
|
|
|
+
|
|
|
+namespace app\api\controller\v1;
|
|
|
+
|
|
|
+use app\BaseController;
|
|
|
+use app\model\api\Sys as SysModel;
|
|
|
+use app\model\api\User as UserModel;
|
|
|
+use app\model\api\Bank as BankModel;
|
|
|
+use app\model\api\UserLove as UserLoveModel;
|
|
|
+use app\model\api\UserCircle;
|
|
|
+use app\model\api\UserCircleLove;
|
|
|
+use app\model\api\Goods;
|
|
|
+use app\model\api\GoodsLove;
|
|
|
+use app\model\api\Order;
|
|
|
+use app\model\api\OrderInfo;
|
|
|
+use app\model\api\OrderMono;
|
|
|
+use app\model\api\Activity;
|
|
|
+use app\model\api\ActivityOrder;
|
|
|
+use app\model\api\Tx as TxModel;
|
|
|
+use app\lib\OrderLib;
|
|
|
+use app\model\api\PayTrade as PayTradeModel;
|
|
|
+use app\model\api\UserDetail as UserDetailModel;
|
|
|
+use app\model\api\UserScoreDetail as UserScoreDetailModel;
|
|
|
+use app\model\api\UserAddress;
|
|
|
+use app\model\api\UserShop;
|
|
|
+use app\model\api\Coupon as CouponModel;
|
|
|
+use app\model\api\UserCoupon as UserCouponModel;
|
|
|
+use app\Request;
|
|
|
+use library\services\UtilService;
|
|
|
+use library\utils\QRcodeComm;
|
|
|
+use library\utils\weixinPay as wxpayApi;
|
|
|
+use think\db\exception\DbException;
|
|
|
+use library\lib\weixina;
|
|
|
+use think\facade\Db;
|
|
|
+use think\Image;
|
|
|
+use think\Route;
|
|
|
+
|
|
|
+class User extends BaseController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 获取用户基本数据
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function init(Request $request)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ $result['nickname'] = $request->user['nickname'];
|
|
|
+ $result['avatar'] = $request->user['avatar'];
|
|
|
+ $result['uip'] = $request->user['uip'];//用户UUID
|
|
|
+ $result['is_bind_parent'] = $request->user['parent_uid']>0?1:0;//是否绑定父级
|
|
|
+ $result['is_mobile'] = empty($request->user['mobile'])?0:1;//是否绑定手机号
|
|
|
+ return app('json')->success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 会员中心信息
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function info(Request $request)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ //基础信息
|
|
|
+ $result['nickname'] = $request->user['nickname'];
|
|
|
+ $result['avatar'] = $request->user['avatar'];
|
|
|
+ $result['uip'] = $request->user['uip'];//用户UIP
|
|
|
+ $result['score'] = $request->user['score'];
|
|
|
+ $result['money'] = $request->user['money'];
|
|
|
+ $result['is_bind_parent'] = $request->user['parent_uid']>0?1:0;//是否绑定父级
|
|
|
+ $result['is_mobile'] = empty($request->user['mobile'])?0:1;//是否绑定手机号
|
|
|
+
|
|
|
+ //动态发布信息
|
|
|
+ $result['loveCount'] = (new UserLoveModel)->where("uid",$request->user["uid"])->count();//关注数
|
|
|
+ $result['diaryCount'] = (new UserCircle)->where("uid",$request->user["uid"])->where("status",">",0)->count();//动态数
|
|
|
+ $result['fansCount'] = (new UserLoveModel)->where("love_uid",$request->user["uid"])->count();//粉丝数
|
|
|
+ $result['lookCount'] = $request->user['look_count'];;//观看量
|
|
|
+ $result['hotCount'] = $result['diaryCount']+$result['fansCount']+$result['lookCount'];//热度=发布量+粉丝数+观看量
|
|
|
+ //订单信息
|
|
|
+ $result['waitPayCount'] = (new Order)->where("uid",$request->user["uid"])->where("status",0)->count(); //待付款
|
|
|
+ $result['waitSendCount'] = (new Order)->where("uid",$request->user["uid"])->where("status",1)->count();//待发货
|
|
|
+ $result['waitAcceptCount'] = (new Order)->where("uid",$request->user["uid"])->where("status",2)->count();//待收货
|
|
|
+ $result['waitCommentCount'] = (new Order)->where("uid",$request->user["uid"])->where("status",3)->count();//待评价
|
|
|
+ //其他信息
|
|
|
+ $result['couponCount'] = (new UserCouponModel)->where("uid",$request->user["uid"])->where("status",0)->where("end_time",">",time())->count();//消费券数
|
|
|
+// $result['logistics']=array(
|
|
|
+// "img"=>"/static/image/test/test1.png",
|
|
|
+// "title"=>"最新物流进展",
|
|
|
+// "content"=>"您的订单已到达杭州转运中心,已入库",
|
|
|
+// );
|
|
|
+ $orderList = (new Order)
|
|
|
+ ->field("id,order_id,name,tel,address,time,pay_time,fa_time,ok_time,status")
|
|
|
+ ->where("uid",$request->user["uid"])
|
|
|
+ ->where("status",1)
|
|
|
+ ->order("id","desc")
|
|
|
+ ->limit(2)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $orderList = empty($orderList) ? [] : $orderList;
|
|
|
+ $orderInfoModel=new OrderInfo();
|
|
|
+ foreach($orderList as $k=>$v){
|
|
|
+ $orderList[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
|
|
|
+ $orderList[$k]["pay_time"] = empty($v["pay_time"]) ? "" : date("Y-m-d H:i:s",$v["pay_time"]);
|
|
|
+ $orderList[$k]["fa_time"] = empty($v["fa_time"]) ? "" : date("Y-m-d H:i:s",$v["fa_time"]);
|
|
|
+ $orderList[$k]["ok_time"] = empty($v["ok_time"]) ? "" : date("Y-m-d H:i:s",$v["ok_time"]);
|
|
|
+ $orderList[$k]["info"] = $orderInfoModel->field("id,p_id,img,title,is_ip_buy,price,count")->where("o_id",$v["id"])->where("uid",$request->user["uid"])->select()->toArray();
|
|
|
+ }
|
|
|
+ $result['orderList'] = $orderList;
|
|
|
+ $result['shop_id'] = 0;
|
|
|
+ $result['shop_name'] = "";
|
|
|
+ $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(!empty($shopData)){
|
|
|
+ $result['shop_id'] = $shopData["id"];
|
|
|
+ $result['shop_name'] = $shopData["name"];
|
|
|
+ }
|
|
|
+ //收益记录数
|
|
|
+ $result['incomeCount'] = (new UserDetailModel)->where("uid",$request->user["uid"])->where("type",1)->count();
|
|
|
+ //下级分成记录数
|
|
|
+ $result['treeIncomeCount'] = (new UserDetailModel)->where("uid",$request->user["uid"])->where("type",1)->where("code","tree_per_income")->count();
|
|
|
+ return app('json')->success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 保存个人资料
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function saveInfo(Request $request)
|
|
|
+ {
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['nickname', '', 'empty', '昵称不存在'],
|
|
|
+ ['avatar', '', 'empty', '头像不存在'],
|
|
|
+ ], $request);
|
|
|
+ $save['nickname'] = $post['nickname'];
|
|
|
+ $save['avatar'] = $post['avatar'];
|
|
|
+ (new UserModel)->where('uid', $request->user['uid'])->save($save);
|
|
|
+ return app('json')->success('保存成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定手机号
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function bindMobile(Request $request){
|
|
|
+ [$code] = UtilService::getMore([
|
|
|
+ ['code', '', 'empty', 'code参数错误'],
|
|
|
+ ], $request, true);
|
|
|
+ if(!empty($request->user['mobile'])){
|
|
|
+ return app('json')->fail("当前账户已绑定过手机号码");
|
|
|
+ }
|
|
|
+ $weixinA = new weixina();
|
|
|
+ $data=$weixinA->getPhoneNumber($code);//新版
|
|
|
+ if(empty($data) || empty($data['purePhoneNumber'])) {
|
|
|
+ return app('json')->fail("绑定失败,请重新绑定01".$weixinA->error);
|
|
|
+ }
|
|
|
+ $save=[
|
|
|
+ "countryCode"=>empty($data['countryCode'])?"":$data['countryCode'],
|
|
|
+ "mobile"=>$data['purePhoneNumber'],
|
|
|
+ ];
|
|
|
+ $r = (new UserModel)->where('uid', $request->user['uid'])->update($save);
|
|
|
+ if(!$r){
|
|
|
+ return app('json')->fail("绑定失败,请重新绑定02");
|
|
|
+ }
|
|
|
+ $result = [];
|
|
|
+ $result['nickname'] = $request->user['nickname'];
|
|
|
+ $result['avatar'] = $request->user['avatar'];
|
|
|
+ $result['token'] = $request->user['token'];
|
|
|
+ $result['uip'] = $request->user['uip'];
|
|
|
+ $result['is_mobile'] = 1;
|
|
|
+ return app('json')->success($result);
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 收藏商品
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function loveGoods(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['id', '', 'empty', '参数错误'],
|
|
|
+ ], $request);
|
|
|
+ $data = (new Goods)->where("id",$post["id"])->where("status",1)->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail("当前商品已下架");
|
|
|
+ }
|
|
|
+ $count = (new GoodsLove)
|
|
|
+ ->where("uid",$request->user['uid'])
|
|
|
+ ->where("goods_id",$data["id"])
|
|
|
+ ->count();
|
|
|
+ $r=0;
|
|
|
+ $msg=$count > 0 ? "取消喜欢" : "喜欢";
|
|
|
+ if($count>0){
|
|
|
+ //取消喜欢
|
|
|
+ $r=(new GoodsLove)->where("uid",$request->user['uid'])->where("goods_id",$data["id"])->delete();
|
|
|
+ }else{
|
|
|
+ //点赞
|
|
|
+ $r=(new GoodsLove)->insert(array("uid"=>$request->user['uid'],"goods_id"=>$data["id"]));
|
|
|
+ }
|
|
|
+ if(empty($r)){
|
|
|
+ return app('json')->fail("{$msg}失败");
|
|
|
+ }
|
|
|
+ return app('json')->success("{$msg}成功");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 点赞圈子
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function loveCircle(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['id', '', 'empty', '参数错误'],
|
|
|
+ ], $request);
|
|
|
+ $data = (new UserCircle)->where("id",$post["id"])->where("status",1)->find();
|
|
|
+ if(empty($data) || $data["uid"] == $request->user['uid']){
|
|
|
+ return app('json')->fail("当前动态不能点赞");
|
|
|
+ }
|
|
|
+ $count = (new UserCircleLove)
|
|
|
+ ->where("uid",$request->user['uid'])
|
|
|
+ ->where("circle_id",$data["id"])
|
|
|
+ ->count();
|
|
|
+ $r=0;
|
|
|
+ $msg=$count > 0 ? "取消点赞" : "点赞";
|
|
|
+ if($count>0){
|
|
|
+ //取消点赞
|
|
|
+ $r=(new UserCircleLove)->where("uid",$request->user['uid'])->where("circle_id",$data["id"])->delete();
|
|
|
+ }else{
|
|
|
+ //点赞
|
|
|
+ $r=(new UserCircleLove)->insert(array("uid"=>$request->user['uid'],"circle_id"=>$data["id"]));
|
|
|
+ }
|
|
|
+ if(empty($r)){
|
|
|
+ return app('json')->fail("{$msg}失败");
|
|
|
+ }
|
|
|
+ $love_count = (new UserCircleLove)->where("circle_id",$data["id"])->count();
|
|
|
+ (new UserCircle)->where('id', $data["id"])->update(["love_count"=>$love_count]);
|
|
|
+ return app('json')->success("{$msg}成功");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加关注
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function loveUser(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['uip', '', 'empty', '用户不存在'],
|
|
|
+ ], $request);
|
|
|
+ $data = (new UserModel())->where("uip",$post["uip"])->find();
|
|
|
+ if(empty($data) || $data["uip"] == $request->user['uip']){
|
|
|
+ return app('json')->fail("用户不存在");
|
|
|
+ }
|
|
|
+ $count = (new UserLoveModel())
|
|
|
+ ->where("uid",$request->user['uid'])
|
|
|
+ ->where("love_uid",$data["uid"])
|
|
|
+ ->count();
|
|
|
+ $r=0;
|
|
|
+ $msg=$count > 0 ? "取消关注" : "关注";
|
|
|
+ if($count>0){
|
|
|
+ //取消关注
|
|
|
+ $r=(new UserLoveModel())->where("uid",$request->user['uid'])->where("love_uid",$data["uid"])->delete();
|
|
|
+ }else{
|
|
|
+ //关注
|
|
|
+ $r=(new UserLoveModel())->insert(array("uid"=>$request->user['uid'],"love_uid"=>$data["uid"],"time"=>time()));
|
|
|
+ }
|
|
|
+ if(empty($r)){
|
|
|
+ return app('json')->fail("{$msg}失败");
|
|
|
+ }
|
|
|
+ return app('json')->success("{$msg}成功");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取用户绑定
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function bankInfo(Request $request){
|
|
|
+ $data = [
|
|
|
+ "bank_type"=>$request->user["bank_type"],
|
|
|
+ "bank_num"=>$request->user["bank_num"],
|
|
|
+ "bank_name"=>$request->user["bank_name"],
|
|
|
+ "bank_ad"=>$request->user["bank_ad"],
|
|
|
+ ];
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取提现信息
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function tixianInfo(Request $request){
|
|
|
+ $sysData = (new SysModel)->where("id",1)->find();
|
|
|
+ $data = [
|
|
|
+ "bank_type"=>$request->user["bank_type"],
|
|
|
+ "bank_num"=>$request->user["bank_num"],
|
|
|
+ "bank_name"=>$request->user["bank_name"],
|
|
|
+ "bank_ad"=>$request->user["bank_ad"],
|
|
|
+ "money"=>$request->user["money"],
|
|
|
+ "tx_limit_money"=>$sysData["tx_limit_money"]
|
|
|
+ ];
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取提现类型
|
|
|
+ * @param Request $request
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function getBankType(Request $request){
|
|
|
+ $data=(new BankModel)
|
|
|
+ ->where("status",1)
|
|
|
+ ->order("seq","desc")
|
|
|
+ ->order("id","desc")
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑绑定
|
|
|
+ * @param Request $request
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function editBank(Request $request){
|
|
|
+ [$bank_type,$bank_name, $bank_num,$bank_ad] = UtilService::getMore([
|
|
|
+ ['bank_type', '', 'empty', '请选择提现方式'],
|
|
|
+ ['bank_name', '', 'empty', '请输入真实姓名'],
|
|
|
+ ['bank_num', '', 'empty', '请输入账号'],
|
|
|
+ ['bank_ad', ''],
|
|
|
+ ], $request, true);
|
|
|
+ if($bank_type!="alipay" && empty($bank_ad)){
|
|
|
+ return app('json')->fail("请输入开户行");
|
|
|
+ }
|
|
|
+ if($bank_type=="alipay"){
|
|
|
+ $bank_ad = "支付宝";
|
|
|
+ }
|
|
|
+ $typeCount=(new BankModel)->where("code",$bank_type)->count();
|
|
|
+ if($typeCount<=0){
|
|
|
+ return app('json')->fail("请选择正确的提现方式");
|
|
|
+ }
|
|
|
+ $save=[
|
|
|
+ "bank_type"=>$bank_type,
|
|
|
+ "bank_name"=>$bank_name,
|
|
|
+ "bank_num"=>$bank_num,
|
|
|
+ "bank_ad"=>$bank_ad,
|
|
|
+ ];
|
|
|
+ (new UserModel)->where("uid",$request->user['uid'])->update($save);
|
|
|
+ return app('json')->success("绑定成功");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 提现申请
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function tixianApply(Request $request){
|
|
|
+ [$money] = UtilService::getMore([
|
|
|
+ ['money', 0, 'is_numeric', '请输入正确的提现金额'],
|
|
|
+ ], $request, true);
|
|
|
+ //缓存
|
|
|
+ $redis = \think\facade\Cache::store('redis');
|
|
|
+ $key = 'user_tixian_' . $request->user['uid'];
|
|
|
+ $bool = $redis->handler()->exists($key);
|
|
|
+ if ($bool) {
|
|
|
+ return app('json')->fail('您的操作过于频繁,请稍等再重试!');
|
|
|
+ }
|
|
|
+ $redis->set($key,1,10);//30秒缓存
|
|
|
+ $user = $request->user;
|
|
|
+ if(empty($user["openid"])){
|
|
|
+ return app('json')->fail('您还未绑定微信');
|
|
|
+ }
|
|
|
+ if(floatval($money)<=0){
|
|
|
+ return app('json')->fail('请输入正确的提现金额');
|
|
|
+ }
|
|
|
+ if(floatval($money)>$user["money"]){
|
|
|
+ return app('json')->fail('您的余额不足,无法提现');
|
|
|
+ }
|
|
|
+ if(empty($user["bank_type"]) || empty($user["bank_num"]) || empty($user["bank_name"])){
|
|
|
+ return app('json')->fail('您还未绑定提现账户');
|
|
|
+ }
|
|
|
+ if($user["bank_type"]!="alipay" && empty($user["bank_ad"])){
|
|
|
+ return app('json')->fail('您还未绑定提现开户行');
|
|
|
+ }
|
|
|
+ $sysData = (new SysModel)->where("id",1)->find();
|
|
|
+ if(floatval($user["money"])<floatval($sysData["tx_limit_money"]) || floatval($money)<floatval($sysData["tx_limit_money"])){
|
|
|
+ return app('json')->fail("满{$sysData['tx_limit_money']}元,才可提现");
|
|
|
+ }
|
|
|
+ //提现手续费
|
|
|
+ $hand_money = $sysData["tx_process_per"] > 0 ? floatval($money) * $sysData["tx_process_per"] / 100 : 0;
|
|
|
+ $hand_money = num_min_format($hand_money);
|
|
|
+ $save=[];
|
|
|
+ $save["uid"] = $user["uid"];
|
|
|
+ $save["bank_type"] = $user["bank_type"];
|
|
|
+ $save["bank_num"] = $user["bank_num"];
|
|
|
+ $save["bank_name"] = $user["bank_name"];
|
|
|
+ $save["bank_ad"] = $user["bank_ad"];
|
|
|
+ $save["money"] = floatval($money);
|
|
|
+ $save["hand_money"] = ($sysData["tx_process_max"] > 0 && $hand_money > $sysData["tx_process_max"]) ? $sysData["tx_process_max"] : $hand_money;
|
|
|
+ $save["tx_money"] = $save["money"] - $save["hand_money"];
|
|
|
+ $save["status"] = 0;
|
|
|
+ $save["time"] = time();
|
|
|
+ try{
|
|
|
+ Db::startTrans();
|
|
|
+ //插入提现申请
|
|
|
+ $tx_id = (new TxModel)->insertGetId($save);
|
|
|
+ if(empty($tx_id)){
|
|
|
+ return app('json')->fail('提交失败');
|
|
|
+ }
|
|
|
+ //更新提现账户余额并添加明细
|
|
|
+ $r= (new UserDetailModel)->txApplyMoney($user["uid"],floatval($money),$tx_id);
|
|
|
+ if(!$r){
|
|
|
+ (new TxModel)->where("id",$tx_id)->delete();
|
|
|
+ return app('json')->fail('提交失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ $redis->delete($key);
|
|
|
+ return app('json')->success('提交成功,等待客服处理');
|
|
|
+ } catch (DbException $db){
|
|
|
+ Db::rollback();
|
|
|
+ return app('json')->fail("订单生成失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关注列表
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function loveList(Request $request)
|
|
|
+ {
|
|
|
+ $pageSize = 20;
|
|
|
+ [$page] = UtilService::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ], $request, true);
|
|
|
+ $data = (new UserLoveModel)
|
|
|
+ ->field("u.id,u2.uip,u2.nickname,u2.avatar")
|
|
|
+ ->alias("u")
|
|
|
+ ->join("user u2", "u2.uid = u.love_uid")
|
|
|
+ ->where("u.uid", $request->user['uid'])
|
|
|
+ ->order("id", "desc")
|
|
|
+ ->page((int)$page, $pageSize)
|
|
|
+ ->select();
|
|
|
+ $loveCount = (new UserLoveModel)->alias("u")->where("u.uid", $request->user['uid'])->count();
|
|
|
+ $tAr = UtilService::getParam([
|
|
|
+ 'id','uip', 'nickname', 'avatar'
|
|
|
+ ], $data);
|
|
|
+ return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize,'loveCount'=>$loveCount]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 我的粉丝
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function fansList(Request $request)
|
|
|
+ {
|
|
|
+ $pageSize = 20;
|
|
|
+ [$page] = UtilService::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ], $request, true);
|
|
|
+ $data = (new UserLoveModel)
|
|
|
+ ->field("u.id,u2.uip,u2.nickname,u2.avatar")
|
|
|
+ ->alias("u")
|
|
|
+ ->join("user u2", "u2.uid = u.uid")
|
|
|
+ ->where("u.love_uid", $request->user['uid'])
|
|
|
+ ->order("id", "desc")
|
|
|
+ ->page((int)$page, $pageSize)
|
|
|
+ ->select();
|
|
|
+ $fansCount = (new UserLoveModel)->alias("u")->where("u.love_uid", $request->user['uid'])->count();
|
|
|
+ $tAr = UtilService::getParam([
|
|
|
+ 'id', 'uip', 'nickname', 'avatar'
|
|
|
+ ], $data);
|
|
|
+ return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize,'fansCount'=>$fansCount]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取门店信息
|
|
|
+ * @param Request $request
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function userShopInfo(Request $request){
|
|
|
+ $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($shopData)){
|
|
|
+ return app('json')->fail("您还没有绑定店铺");
|
|
|
+ }
|
|
|
+ return app('json')->success($shopData->toArray());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取门店列表
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function getShopList(Request $request){
|
|
|
+ [$longitude,$latitude] = UtilService::getMore([
|
|
|
+ ['longitude', ""],
|
|
|
+ ['latitude', ""],
|
|
|
+ ], $request, true);
|
|
|
+ //经纬度排序
|
|
|
+ $lbsOrder="id desc";
|
|
|
+ if(!empty($longitude) && !empty($latitude)){
|
|
|
+ $lng = $longitude;
|
|
|
+ $lat = $latitude;
|
|
|
+ $lbsOrder = 'ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS(('.$lng.' * 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380';
|
|
|
+ }
|
|
|
+ $data = (new UserShop)
|
|
|
+ ->field("id,area, address,name,tel,lx_name,longitude,latitude")
|
|
|
+ ->where("is_show",1)
|
|
|
+ ->orderRaw($lbsOrder)
|
|
|
+ ->select();
|
|
|
+ $data = empty($data)?[]:$data->toArray();
|
|
|
+ return app('json')->success(['list' =>$data, 'pageSize' => 100]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的地址列表
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function addressList(Request $request){
|
|
|
+ $pageSize = 20;
|
|
|
+ [$page] = UtilService::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ], $request, true);
|
|
|
+ $data = (new UserAddress)
|
|
|
+ ->where("uid", $request->user['uid'])
|
|
|
+ ->order("time", "desc")
|
|
|
+ ->page((int)$page, $pageSize)
|
|
|
+ ->select();
|
|
|
+ $tAr = UtilService::getParam([
|
|
|
+ 'id','area', 'address', 'name', 'tel', 'defalut'
|
|
|
+ ], $data);
|
|
|
+ return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除地址
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function addressDel(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['id','','empty','参数错误'],
|
|
|
+ ],$request);
|
|
|
+ $r = (new UserAddress)->where("id",$post["id"])->where("uid",$request->user["uid"])->delete();
|
|
|
+ if($r){
|
|
|
+ return app('json')->success("删除成功");
|
|
|
+ }else{
|
|
|
+ return app('json')->fail("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户券列表
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function couponList(Request $request){
|
|
|
+ $pageSize = 20;
|
|
|
+ [$page,$type] = UtilService::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ['type',''],
|
|
|
+ ], $request, true);
|
|
|
+ //清除失效的券
|
|
|
+ (new UserCouponModel)->where("uid", $request->user['uid'])->where("status",0)->where("end_time","<",time())->update(["status"=>-1]);
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["uid","=",$request->user['uid']];
|
|
|
+ //未使用
|
|
|
+ if($type=="using"){
|
|
|
+ $where[] = ["status","=",0];
|
|
|
+ }
|
|
|
+ //已经使用
|
|
|
+ if($type=="used"){
|
|
|
+ $where[] = ["status","=",1];
|
|
|
+ }
|
|
|
+ //已过期
|
|
|
+ if($type=="nouser"){
|
|
|
+ $where[] = ["status","=",-1];
|
|
|
+ }
|
|
|
+ $data = (new UserCouponModel)
|
|
|
+ ->where($where)
|
|
|
+ ->order("time", "desc")
|
|
|
+ ->page((int)$page, $pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["start_time"] = date("Y.m.d",$v["start_time"]);
|
|
|
+ $data[$k]["end_time"] = date("Y.m.d",$v["end_time"]);
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户领券
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function gainCoupon(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['coupon_id','','empty','参数错误'],
|
|
|
+ ],$request);
|
|
|
+ $data = (new CouponModel)->where("id",$post["coupon_id"])->where("status",1)->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail("当前优惠券不支持领取");
|
|
|
+ }
|
|
|
+ $userCouponData = (new UserCouponModel)->where("coupon_id",$post["coupon_id"])->where("uid",$request->user["uid"])->find();
|
|
|
+ if(!empty($userCouponData)){
|
|
|
+ return app('json')->fail("您已经领取过该优惠券了");
|
|
|
+ }
|
|
|
+ $ntime = time();
|
|
|
+ $save=[
|
|
|
+ "uid"=>$request->user["uid"],
|
|
|
+ "coupon_id"=>$data["id"],
|
|
|
+ "title"=>$data["title"],
|
|
|
+ "price"=>$data["price"],
|
|
|
+ "limit_price"=>$data["limit_price"],
|
|
|
+ "day"=>$data["day"],
|
|
|
+ "status"=>0,
|
|
|
+ "time"=>$ntime,
|
|
|
+ "start_time"=>strtotime(date("Y-m-d",$ntime)),
|
|
|
+ "end_time"=>$ntime+$data["day"]*24*60*60,
|
|
|
+ ];
|
|
|
+ $r = (new UserCouponModel)->insert($save);
|
|
|
+ if($r){
|
|
|
+ return app('json')->success("领取成功");
|
|
|
+ }else{
|
|
|
+ return app('json')->fail("领取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加编辑地址
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function addressAdd(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['id',''],
|
|
|
+ ['area','','empty','请选择省市区'],
|
|
|
+ ['address','','empty','请填写详细地址'],
|
|
|
+ ['name','','empty','请填写姓名'],
|
|
|
+ ['tel','','empty','请填写电话'],
|
|
|
+ ],$request);
|
|
|
+ $post["time"] = time();
|
|
|
+ $id = $post["id"];
|
|
|
+ unset($post["id"]);
|
|
|
+ $r=0;
|
|
|
+ if(empty($id) || $id=="0"){
|
|
|
+ $post["uid"]=$request->user["uid"];
|
|
|
+ $r = (new UserAddress)->insert($post);
|
|
|
+ }else{
|
|
|
+ $r = (new UserAddress)->where("id",$id)->update($post);
|
|
|
+ }
|
|
|
+ if($r){
|
|
|
+ return app('json')->success("数据保存成功");
|
|
|
+ }else{
|
|
|
+ return app('json')->fail("数据保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户二维码
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function getUipErcode(Request $request){
|
|
|
+ $sysData = (new SysModel)->where("id",1)->find();
|
|
|
+ //二维码生成器
|
|
|
+ $QRcodeComm = new QRcodeComm();
|
|
|
+ $url=$sysData['system_url']."/pushurl/".$request->user['uip'];
|
|
|
+ $urlPath = $QRcodeComm->getPngErcode($url);
|
|
|
+ $savePath = $sysData['system_url'] . $urlPath;
|
|
|
+ if(!empty($request->user["ercode"])){
|
|
|
+ $rootPath = app()->getRootPath()."/public/resource".explode("resource",$request->user["ercode"])[1];
|
|
|
+ if(file_exists($rootPath)){
|
|
|
+ unlink($rootPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (new UserModel)->where("uid",$request->user["uid"])->update(array("ercode"=>$savePath));
|
|
|
+ return app('json')->success(['url' => $savePath]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取下单初始信息
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function getProBuyInfo(Request $request){
|
|
|
+ [$p_id,$is_ip_buy,$longitude,$latitude] = UtilService::getMore([
|
|
|
+ ['p_id','','empty','商品参数错误'],
|
|
|
+ ['is_ip_buy','0'],
|
|
|
+ ['longitude',''],
|
|
|
+ ['latitude',''],
|
|
|
+ ],$request,true);
|
|
|
+
|
|
|
+
|
|
|
+ $is_ip_buy = (int)$is_ip_buy==0?0:1;
|
|
|
+ $proData = (new Goods)->where("id",(int)$p_id)->where("status",1)->find();
|
|
|
+ if(empty($proData)){
|
|
|
+ return app('json')->fail("当前商品已下架");
|
|
|
+ }
|
|
|
+ $proData=$proData->toArray();
|
|
|
+ if($proData["limit"]<=0){
|
|
|
+ return app('json')->fail("当前商品限购不可购买");
|
|
|
+ }
|
|
|
+ if($is_ip_buy==1 && ($proData["is_ip"]==0 || !empty($proData["uid"]))){
|
|
|
+ return app('json')->fail("当前商品不可买断");
|
|
|
+ }
|
|
|
+ $price = floatval($proData["price"]);
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $price = floatval($proData["ip_price"]);
|
|
|
+ }
|
|
|
+ $img = explode(",", $proData["imgs"])[0];
|
|
|
+ $data=[
|
|
|
+ "score"=> $is_ip_buy == 1 ? 0 : $request->user["score"],
|
|
|
+ "use_score"=>0,
|
|
|
+ "is_score"=>1,
|
|
|
+ "proMoney"=>0,
|
|
|
+ "allMoney"=>0,
|
|
|
+ "couponMoney"=>0,
|
|
|
+ "coupon"=>[
|
|
|
+ "id"=>"",
|
|
|
+ "limit"=>0,//满多少可用
|
|
|
+ "price"=>0,//金额
|
|
|
+ ],
|
|
|
+ "mono"=>"",
|
|
|
+ "address"=>[
|
|
|
+ "id"=>"",
|
|
|
+ "address"=>"",
|
|
|
+ "name"=>"",
|
|
|
+ "tel"=>"",
|
|
|
+ ],
|
|
|
+ "shop"=>[
|
|
|
+ "id"=>"",
|
|
|
+ "address"=>"",
|
|
|
+ "name"=>"",
|
|
|
+ "tel"=>"",
|
|
|
+ ],
|
|
|
+ "pro"=>[],
|
|
|
+ ];
|
|
|
+ //商品信息
|
|
|
+ $data["pro"][]=[
|
|
|
+ "id"=>$proData["id"],
|
|
|
+ "img"=>$img,
|
|
|
+ "count"=>1,
|
|
|
+ "status"=>$proData["status"],
|
|
|
+ "title"=>$proData["title"],
|
|
|
+ "price"=>$price,
|
|
|
+ "ip_income_per"=>$proData["ip_income_per"],
|
|
|
+ "is_ip_buy"=>$is_ip_buy,
|
|
|
+ "limit"=>$is_ip_buy==1 ? 1 : $proData["limit"],
|
|
|
+ "data"=>empty($proData["data"])?[]:unserialize($proData["data"])
|
|
|
+ ];
|
|
|
+ //默认地址信息
|
|
|
+ $addressData = (new UserAddress)->where("uid", $request->user['uid'])->order("time", "desc")->find();
|
|
|
+ if(!empty($addressData)){
|
|
|
+ $data["address"]["id"] = $addressData["id"];
|
|
|
+ $data["address"]["address"] = $addressData["area"].$addressData["address"];
|
|
|
+ $data["address"]["name"] = $addressData["name"];
|
|
|
+ $data["address"]["tel"] = $addressData["tel"];
|
|
|
+ $data["address"]["lx_name"] = "";
|
|
|
+ }
|
|
|
+ //默认店铺地址经纬度排序
|
|
|
+ $lbsOrder="id desc";
|
|
|
+ if(!empty($longitude) && !empty($latitude)){
|
|
|
+ $lng = $longitude;
|
|
|
+ $lat = $latitude;
|
|
|
+ $lbsOrder = 'ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((latitude * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 ) * COS((latitude * 3.1415) / 180 ) *COS(('.$lng.' * 3.1415) / 180 - (longitude * 3.1415) / 180 ) ) * 6380';
|
|
|
+ }
|
|
|
+ $shopData = (new UserShop)->where("is_show",1)->orderRaw($lbsOrder)->find();
|
|
|
+ if(!empty($shopData)){
|
|
|
+ $data["shop"]["id"] = $shopData["id"];
|
|
|
+ $data["shop"]["address"] = $shopData["address"];
|
|
|
+ $data["shop"]["name"] = $shopData["name"];
|
|
|
+ $data["shop"]["tel"] = $shopData["tel"];
|
|
|
+ $data["shop"]["lx_name"] = $shopData["lx_name"];
|
|
|
+ }
|
|
|
+ $data["buyTypeData"]=[["id"=>0,"title"=>"商家配送","is_show"=>0,"is_default"=>0],["id"=>1,"title"=>"门店自提","is_show"=>1,"is_default"=>1]];
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取报名表单信息
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function activityFromInfo(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['id', '','empty','参数错误'],
|
|
|
+ ], $request);
|
|
|
+ $data = (new Activity)->where('is_show', 1)->where('id', $post["id"])->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail("数据获取失败");
|
|
|
+ }
|
|
|
+ $data = $data->toArray();
|
|
|
+ $acData=[];
|
|
|
+ $acData["id"] = $data["id"];
|
|
|
+ $acData["img"] = empty($data["imgs"]) ? "" : explode(",",$data["imgs"])[0];
|
|
|
+ $acData["title"] = $data["title"];
|
|
|
+ $acData["status"] = $data["time"] > time() ? 1 : 0;
|
|
|
+ $acData["time"] = date("Y.m.d",$data["time"]);
|
|
|
+ $acData["deposits_price"] = floatval($data["deposits_price"]);
|
|
|
+ $acData["data"] = empty($data["data"]) ? [] : unserialize($data["data"]);
|
|
|
+ $acData["mono"] = "";
|
|
|
+ foreach($acData["data"] as $k=>$v){
|
|
|
+ $acData["data"][$k]["value"]="";
|
|
|
+ if(!empty($v["parms"])){
|
|
|
+ $acData["data"][$k]["index"]=0;
|
|
|
+ $acData["data"][$k]["parms"] = array_merge(["选择{$v['title']}"],$v["parms"]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return app('json')->success($acData);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 活动报名订单提交[第一步]
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function subActivityOrder(Request $request){
|
|
|
+ [$id,$data] = UtilService::getMore([
|
|
|
+ ['id','','empty','请选择要报名的活动'],
|
|
|
+ ['data','','empty','请填写报名信息'],
|
|
|
+ ],$request,true);
|
|
|
+ //缓存
|
|
|
+ $redis = \think\facade\Cache::store('redis');
|
|
|
+ $key = 'order_sub_' . $request->user['uid'];
|
|
|
+ $bool = $redis->handler()->exists($key);
|
|
|
+ if ($bool) {
|
|
|
+ return app('json')->fail('请务重复操作,请稍等在重试!');
|
|
|
+ }
|
|
|
+ $redis->set($key,1,5);//5秒缓存
|
|
|
+ if(empty($id) || empty($data)){
|
|
|
+ return app('json')->fail('提交参数有误01');
|
|
|
+ }
|
|
|
+ $data = json_decode($data,true);
|
|
|
+ if(!is_array($data)){
|
|
|
+ return app('json')->fail('提交参数有误02');
|
|
|
+ }
|
|
|
+
|
|
|
+ $activityData = (new Activity)->where("id",(int)$id)->where("is_show",1)->find();
|
|
|
+ if(empty($activityData)){
|
|
|
+ return app('json')->fail("当前活动已下架");
|
|
|
+ }
|
|
|
+ $activityData=$activityData->toArray();
|
|
|
+ if($activityData["time"]<=time()){
|
|
|
+ return app('json')->fail("当前活动已经结束");
|
|
|
+ }
|
|
|
+ $price = floatval($activityData["deposits_price"]);
|
|
|
+// if($price<=0){
|
|
|
+// return app('json')->fail("活动报名费用错误");
|
|
|
+// }
|
|
|
+ $img = explode(",", $activityData["imgs"])[0];
|
|
|
+ $allMoney = $price;//订单商品费用
|
|
|
+ $total_money = $allMoney;//订单总费用
|
|
|
+ $payMoney = $total_money;//订单需支付费用
|
|
|
+ $payMoney = $payMoney <= 0 ? 0 : $payMoney;
|
|
|
+ $nowTime = time();
|
|
|
+ //验证报名参数提交
|
|
|
+ $parmData = empty($activityData["data"]) ? [] : unserialize($activityData["data"]);
|
|
|
+ if(empty($parmData)){
|
|
|
+ return app('json')->fail("系统参数错误");
|
|
|
+ }
|
|
|
+ $newData = [];
|
|
|
+ foreach($parmData as $k=>$v){
|
|
|
+ $itemData=[
|
|
|
+ "title"=>trim($v["title"]),
|
|
|
+ "value"=>"",
|
|
|
+ ];
|
|
|
+ $check = false;
|
|
|
+ foreach($data as $dk=>$dv){
|
|
|
+ if($dv["title"]==$v["title"]){
|
|
|
+ //验证必填项
|
|
|
+ if((int)$v["required"]==1 && empty($dv["value"])){
|
|
|
+ return app('json')->fail("{$v['title']}为必填项");
|
|
|
+ }
|
|
|
+ //下拉框验证
|
|
|
+ if(!empty($dv["value"]) && $v["type"]=="select" && !in_array($dv["value"],$v["parms"])){
|
|
|
+ return app('json')->fail("{$v['title']}选项不存在");
|
|
|
+ }
|
|
|
+ $itemData["value"]=trim($dv["value"]);
|
|
|
+ $check = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!$check){
|
|
|
+ return app('json')->fail("请填写{$v['title']}");
|
|
|
+ }
|
|
|
+ $newData[]=$itemData;
|
|
|
+ }
|
|
|
+ if(empty($newData)){
|
|
|
+ return app('json')->fail("参数整合错误");
|
|
|
+ }
|
|
|
+ //主订单数据
|
|
|
+ $save=[];
|
|
|
+ $save['uid'] = $request->user['uid'];
|
|
|
+ $save['order_id'] = makeOrderId($request->user['uid'],"A");
|
|
|
+ $save['pay_type'] = 'wxpay';//目前只支持微信支付
|
|
|
+ $save['total_money'] = $total_money;//订单总金额
|
|
|
+ $save['all_money'] = $allMoney;//商品中金额
|
|
|
+ $save['pay_money'] = $payMoney;//实际支付金额
|
|
|
+ $save['balance'] = 0;//余额支付了多少(目前没有余额支付)
|
|
|
+ $save['status'] = $payMoney <= 0 ? 1 : 0;
|
|
|
+ $save['pay_time'] = $payMoney <= 0 ? time() : 0;
|
|
|
+ $save['time'] = $nowTime;
|
|
|
+ $save['activity_id'] = $activityData["id"];
|
|
|
+ $save['data'] = serialize($newData);
|
|
|
+ $save['activity_data']= serialize([
|
|
|
+ "id"=>$activityData["id"],
|
|
|
+ "img"=>$img,
|
|
|
+ "title"=>$activityData["title"],
|
|
|
+ "address"=>$activityData["address"],
|
|
|
+ "deposits_price"=>$activityData["deposits_price"],
|
|
|
+ "time_str"=>$activityData["time_str"],
|
|
|
+ "time"=>date("Y-m-d H:i:s",$activityData["time"]),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ try{
|
|
|
+ Db::startTrans();
|
|
|
+ $o_id = (new ActivityOrder)->insertGetId($save);
|
|
|
+ if(empty($o_id)){
|
|
|
+ return app('json')->fail("报名订单提交失败");
|
|
|
+ }
|
|
|
+ //不需要支付
|
|
|
+ if($save['status']==1){
|
|
|
+ Db::commit();
|
|
|
+ return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
|
|
|
+ }
|
|
|
+ if(empty($request->user['openid'])){
|
|
|
+ return app('json')->fail('用户还未绑定微信!');
|
|
|
+ }
|
|
|
+ //清理之前支付凭证 || 防止重复购买
|
|
|
+ $payTrade = (new PayTradeModel)
|
|
|
+ ->where("uid",$request->user["uid"])
|
|
|
+ ->where("o_id",$o_id)
|
|
|
+ ->where("type","activity")
|
|
|
+ ->where("status",0)
|
|
|
+ ->where("time","<",time() - 7*24*60*60)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $wxpay = new wxpayApi();
|
|
|
+ foreach ($payTrade as $v) {
|
|
|
+// if($v['pay_type'] == 'wxpay') {
|
|
|
+// $result = $wxpay->closeOrder($v['pay_no']);
|
|
|
+// }
|
|
|
+ (new PayTradeModel)->where("id",$v['id'])->where("status",0)->delete();
|
|
|
+ }
|
|
|
+ $mtime = microtime(true)*10000;
|
|
|
+ $payOn = "A".date("Ymd").$mtime .rand(1000,9000) . $request->user['uid'];
|
|
|
+ $out_trade_no="";
|
|
|
+ $payType = $save["pay_type"];
|
|
|
+ //添加交易记录
|
|
|
+ $trade = [
|
|
|
+ 'uid' => $request->user['uid'],
|
|
|
+ 'o_id' => $o_id,
|
|
|
+ 'order_id' =>$save["order_id"],
|
|
|
+ 'pay_no' => $payOn,
|
|
|
+ 'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
|
|
|
+ 'pay_type' => $payType,
|
|
|
+ 'money' => $payMoney,
|
|
|
+ 'type' => 'activity',
|
|
|
+ 'd_json' => serialize(['orderId'=>$save["order_id"],"give_score"=>0]),
|
|
|
+ 'time' => time(),
|
|
|
+ 'status' => 0,
|
|
|
+ ];
|
|
|
+ $r=(new PayTradeModel)->insert($trade);
|
|
|
+ if(!$r){
|
|
|
+ return app('json')->fail('支付信息获取失败!');
|
|
|
+ }
|
|
|
+ $clictip = get_client_ip();
|
|
|
+ if(empty($clictip)){
|
|
|
+ $clictip = $request->ip();
|
|
|
+ }
|
|
|
+ $payData = $wxpay->wxmpPay([
|
|
|
+ 'description' =>"微信小程序活动报名",
|
|
|
+ 'out_trade_no' => $payOn,
|
|
|
+ 'total' => $payMoney,
|
|
|
+ 'openid' => $request->user['openid'],
|
|
|
+ 'payer_client_ip'=>$clictip,
|
|
|
+ ]);
|
|
|
+ if(empty($payData)){
|
|
|
+ return app('json')->fail($wxpay->errorMsg);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ $redis->delete($key);
|
|
|
+ return app('json')->success([
|
|
|
+ 'jsApiParameters'=> $payData,
|
|
|
+ 'pay_no' => $payOn,
|
|
|
+ 'order_id' => $save["order_id"],
|
|
|
+ "status" => $save['status'],
|
|
|
+ "money" => $payMoney,
|
|
|
+ ]);
|
|
|
+ } catch (DbException $db){
|
|
|
+ Db::rollback();
|
|
|
+ return app('json')->fail("订单生成失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取支付报名订单详情
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function payActivityOrderInfo(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ $data = (new ActivityOrder)
|
|
|
+ ->field("order_id,total_money,all_money,pay_money,status,time")
|
|
|
+ ->where("order_id",$order_id)
|
|
|
+ ->where("uid",$request->user["uid"])
|
|
|
+ ->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail('信息不存在!');
|
|
|
+ }
|
|
|
+ $data=$data->toArray();
|
|
|
+ if($data["status"]==0 && $data["time"]<time() - 30*60){
|
|
|
+ (new ActivityOrder)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
|
|
|
+ $data["status"]==-1;
|
|
|
+ }
|
|
|
+ $data["time"] = date("Y-m-d H:i:s",$data["time"]);
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交订单[第一步]
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function subOrder(Request $request){
|
|
|
+ [$p_id,$address_id,$shop_id,$count,$mono,$coupon_id,$is_ip_buy,$is_score,$type] = UtilService::getMore([
|
|
|
+ ['p_id','','empty','请选择要购买的商品'],
|
|
|
+ ['address_id',''],
|
|
|
+ ['shop_id',''],
|
|
|
+ ['count','','is_numeric','请选择购买数量'],
|
|
|
+ ['mono',''],
|
|
|
+ ['coupon_id',''],
|
|
|
+ ['is_ip_buy','0'],
|
|
|
+ ['is_score','0'],
|
|
|
+ ['type','send'],
|
|
|
+ ],$request,true);
|
|
|
+ if(!in_array($type,["shop","send"])){
|
|
|
+ return app('json')->fail('参数错误!');
|
|
|
+ }
|
|
|
+ if($type=="shop"){
|
|
|
+ $address_id = "";
|
|
|
+ }else{
|
|
|
+ $shop_id = "";
|
|
|
+ }
|
|
|
+ if((int)$is_ip_buy==1){
|
|
|
+ $address_id = "";
|
|
|
+ $shop_id = "";
|
|
|
+ }
|
|
|
+ if((int)$is_ip_buy==0 && $type=="send" && empty($address_id)){
|
|
|
+ return app('json')->fail('请选择收货地址');
|
|
|
+ }
|
|
|
+ if((int)$is_ip_buy==0 && $type=="shop" && empty($shop_id)){
|
|
|
+ return app('json')->fail('请选择自提门店!');
|
|
|
+ }
|
|
|
+ if($type=="shop" && $is_ip_buy==1){
|
|
|
+ return app('json')->fail('买断不可选择门店自提!');
|
|
|
+ }
|
|
|
+ //用户缓存
|
|
|
+ $redis = \think\facade\Cache::store('redis');
|
|
|
+ $key = 'order_sub_' . $request->user['uid'];
|
|
|
+ $bool = $redis->handler()->exists($key);
|
|
|
+ if ($bool) {
|
|
|
+ return app('json')->fail('请务重复操作,请稍等在重试!');
|
|
|
+ }
|
|
|
+ $redis->set($key,1,5);//5秒缓存
|
|
|
+
|
|
|
+ $is_ip_buy = (int)$is_ip_buy == 1 ? 1 : 0;
|
|
|
+ $is_score = (int)$is_score == 1 && $is_ip_buy==0 ? 1 : 0;//普通购买才可以使用积分
|
|
|
+ $is_ip_buy = (int)$is_ip_buy == 0 ? 0 : 1;
|
|
|
+ $coupon_id = $is_ip_buy == 1 ? 0 : (int)$coupon_id;
|
|
|
+ $count = $is_ip_buy == 1 ? 1 : (int)$count;
|
|
|
+
|
|
|
+ $proData = (new Goods)->where("id",(int)$p_id)->where("status",1)->find();
|
|
|
+ if(empty($proData)){
|
|
|
+ return app('json')->fail("当前商品已下架");
|
|
|
+ }
|
|
|
+ $proData=$proData->toArray();
|
|
|
+ if($proData["limit"]<=0 || $count>$proData['limit']){
|
|
|
+ return app('json')->fail("当前商品单次限购".$proData['limit']."件");
|
|
|
+ }
|
|
|
+ if($is_ip_buy==1 && ($proData["is_ip"]==0 || !empty($proData["uid"]))){
|
|
|
+ return app('json')->fail("当前商品不可买断");
|
|
|
+ }
|
|
|
+
|
|
|
+ //IP商品缓存
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $ipkey = 'order_sub_ip_' . $p_id;
|
|
|
+ $ipbool = $redis->handler()->exists($ipkey);
|
|
|
+ if($ipbool){
|
|
|
+ return app('json')->fail('当前购买人数太多,请稍等再尝试!');
|
|
|
+ }
|
|
|
+ $redis->set($ipkey,1,5);//5秒缓存
|
|
|
+ }
|
|
|
+
|
|
|
+ $price = floatval($proData["price"]);
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $price = floatval($proData["ip_price"]);
|
|
|
+ }
|
|
|
+ if($price<=0){
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $redis->delete($ipkey);
|
|
|
+ }
|
|
|
+ return app('json')->fail("商品价格错误");
|
|
|
+ }
|
|
|
+ $img = explode(",", $proData["imgs"])[0];
|
|
|
+ //优惠券
|
|
|
+ $couponData=null;
|
|
|
+ $couponMoney=0;
|
|
|
+ if(!empty($coupon_id)){
|
|
|
+ $couponData = (new UserCouponModel)->where("id",$coupon_id)->where("uid",$request->user["uid"])->where("status",0)->where("end_time",">",time())->find();
|
|
|
+ if(empty($couponData)){
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $redis->delete($ipkey);
|
|
|
+ }
|
|
|
+ return app('json')->fail("当前优惠券不可用");
|
|
|
+ }
|
|
|
+ $couponMoney = $couponData["price"];
|
|
|
+ }
|
|
|
+ //收货地址
|
|
|
+ $addressData=null;
|
|
|
+ if(!empty($address_id)){
|
|
|
+ $addressData = (new UserAddress)->where("id",$address_id)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($addressData)){
|
|
|
+ return app('json')->fail("请选择收货地址02");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //门店地址
|
|
|
+ $shopData=null;
|
|
|
+ if(!empty($shop_id)){
|
|
|
+ $shopData = (new UserShop)->where("id",$shop_id)->where("is_show",1)->find();
|
|
|
+ if(empty($shopData)){
|
|
|
+ return app('json')->fail("请选择自提门店");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $nowTime = time();
|
|
|
+ //订单详情数据
|
|
|
+ $infoData=[];
|
|
|
+ $info=[];
|
|
|
+ $info["o_id"] = "";
|
|
|
+ $info["uid"] = $request->user['uid'];
|
|
|
+ $info["p_id"] = $proData["id"];
|
|
|
+ $info["title"] = $proData["title"];
|
|
|
+ $info["img"] = $img;
|
|
|
+ $info["count"] = $count;
|
|
|
+ $info["price"] = $price;
|
|
|
+ $info["money"] = $price*$count;
|
|
|
+ $info["give_score"]= $is_ip_buy == 1 ? 0 : (int)$proData["give_score"] * $count;
|
|
|
+ $info["is_ip_buy"] = $is_ip_buy;
|
|
|
+ $info["add_time"] = $nowTime;
|
|
|
+ $infoData[]=$info;
|
|
|
+ $give_score = 0;
|
|
|
+ $allMoney = 0;
|
|
|
+ $postageMoney = 0;
|
|
|
+ foreach($infoData as $k=>$v){
|
|
|
+ $allMoney+=$v["money"];
|
|
|
+ $give_score+=$v["give_score"];
|
|
|
+ }
|
|
|
+ if(!empty($couponData) && $allMoney<$couponData["limit_price"]){
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $redis->delete($ipkey);
|
|
|
+ }
|
|
|
+ return app('json')->fail("当前优惠券满{$couponData['limit_price']}可用");
|
|
|
+ }
|
|
|
+ $total_money = $allMoney + $postageMoney;
|
|
|
+ $payMoney = $total_money - $couponMoney;
|
|
|
+ $payMoney = $payMoney <= 0 ? 0 : $payMoney;
|
|
|
+
|
|
|
+ //使用积分1:1元
|
|
|
+ $score=0;
|
|
|
+ if($payMoney>0 && $request->user["score"]>0 && $is_score==1){
|
|
|
+ $score = $request->user["score"] > $payMoney ? (int)$payMoney : (int)$request->user["score"];
|
|
|
+ }
|
|
|
+ $payMoney = $payMoney - $score;
|
|
|
+ //目前先不能支付0元
|
|
|
+// if($payMoney<=0){
|
|
|
+// return app('json')->fail("订单金额错误");
|
|
|
+// }
|
|
|
+ //主订单数据
|
|
|
+ $save=[];
|
|
|
+ $save['uid'] = $request->user['uid'];
|
|
|
+ $save['order_id'] = makeOrderId($request->user['uid']);
|
|
|
+ $save['pay_type'] = 'wxpay';//目前只支持微信支付
|
|
|
+ $save['total_money'] = $total_money;//订单总金额
|
|
|
+ $save['all_money'] = $allMoney;//商品中金额
|
|
|
+ $save['pay_money'] = $payMoney;//实际支付金额
|
|
|
+ $save['balance'] = 0;//余额支付了多少(目前没有余额支付)
|
|
|
+ $save['postage'] = $postageMoney;//邮费(目前不需要)
|
|
|
+
|
|
|
+ $save['name'] = empty($addressData) ? "" : $addressData["name"];
|
|
|
+ $save['tel'] = empty($addressData) ? "" : $addressData["tel"];
|
|
|
+ $save['address'] = empty($addressData) ? "" : $addressData["area"].$addressData["address"];
|
|
|
+ $save['shop_id'] = empty($shopData) ? 0 : $shopData["id"];
|
|
|
+ $save['type'] = $type;
|
|
|
+
|
|
|
+ $save['coupon_id'] = $coupon_id;
|
|
|
+ $save['coupon_money'] = $couponMoney;
|
|
|
+ $save['is_ip_buy'] = $is_ip_buy;
|
|
|
+ $save['status'] = $payMoney <= 0 ? 1 : 0;
|
|
|
+ $save['pay_time'] = $payMoney <= 0 ? time() : 0;
|
|
|
+ $save['score'] = $score;//使用积分
|
|
|
+ $save["mono"] = $mono;//订单备注
|
|
|
+ $save['time'] = $nowTime;
|
|
|
+ $save['give_score'] = $give_score;//赠送积分
|
|
|
+
|
|
|
+ try{
|
|
|
+ Db::startTrans();
|
|
|
+ $o_id = (new Order)->insertGetId($save);
|
|
|
+ if(empty($o_id)){
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $redis->delete($ipkey);
|
|
|
+ }
|
|
|
+ return app('json')->fail("订单生成失败");
|
|
|
+ }
|
|
|
+ foreach($infoData as $k=>$v){
|
|
|
+ $infoData[$k]["o_id"] = $o_id;
|
|
|
+ }
|
|
|
+ (new OrderInfo)->insertAll($infoData);
|
|
|
+ //消费券
|
|
|
+ if(!empty($couponData)) {
|
|
|
+ (new UserCouponModel)->where("id",$couponData["id"])->update(["status"=>1]);
|
|
|
+ }
|
|
|
+ //积分
|
|
|
+ if($score>0){
|
|
|
+ $mono = "商城购买使用积分抵扣";
|
|
|
+ (new UserScoreDetailModel)->payScore($request->user["uid"],$score,"outcome_score",$mono,["o_id"=>$o_id]);
|
|
|
+ }
|
|
|
+ //如果支付为0则直接送积分
|
|
|
+ if($save['status']==1 && $give_score>0){
|
|
|
+ (new UserScoreDetailModel)->incomeScore($request->user["uid"], $give_score, "","income_score",["o_id"=>$o_id]);
|
|
|
+ }
|
|
|
+ //系统信息
|
|
|
+ $sysData = (new SysModel)->where("id",1)->find();
|
|
|
+ //普通购买
|
|
|
+ if($save['status']==1 && $payMoney>0 && $save["is_ip_buy"]==0){
|
|
|
+ //上级用户
|
|
|
+ if($request->user["parent_uid"]>0){
|
|
|
+ $parentData = (new UserModel)->where("uid",$request->user["parent_uid"])->where("status",1)->find();
|
|
|
+ //一级用户
|
|
|
+ if(!empty($parentData) && $sysData['tree_income_per']>0 && $sysData['tree_income_per']<=100){
|
|
|
+ $treepermono = "推广用户购买商品获得分成";//分成内容
|
|
|
+ $treePerMoney = $payMoney*((int)$sysData['tree_income_per']/100);//分成收益金额
|
|
|
+ if($treePerMoney>0){
|
|
|
+ // return true;//暂时关闭分成
|
|
|
+ (new UserDetailModel)->goodsIncome($request->user["parent_uid"],$treePerMoney,"tree_per_income",$treepermono,["cash_uid"=>$save["uid"],"p_id"=>$proData["id"],"o_id"=>$o_id]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //二级用户
|
|
|
+ if(!empty($parentData) && $parentData["parent_uid"] > 0 && $sysData['tree_income_per_two']>0 && $sysData['tree_income_per_two']<=100){
|
|
|
+ $treepermonoTwo = "二级推广用户购买商品获得分成";//分成内容
|
|
|
+ $treePerMoneyTwo = $payMoney*((int)$sysData['tree_income_per_two']/100);//分成收益金额
|
|
|
+ if($treePerMoneyTwo>0){
|
|
|
+ // return true;//暂时关闭分成
|
|
|
+ (new UserDetailModel)->goodsIncome($parentData["parent_uid"],$treePerMoneyTwo,"tree_per_income",$treepermonoTwo,["cash_uid"=>$save["uid"],"p_id"=>$proData["id"],"o_id"=>$o_id]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果不需要支付则直接算IP分成
|
|
|
+ if($save['status']==1 && $payMoney>0 && $save["is_ip_buy"]==0 && !empty($proData["uid"]) && $proData["is_ip"]==1){
|
|
|
+// $sysPer=$sysData['ip_income_per'];//分成比例,后台设置
|
|
|
+ $sysPer=$proData['ip_income_per'];//如果是单个商品则用这条
|
|
|
+ if($sysPer>0 && $sysPer<=100){
|
|
|
+ $permono = "用户购买IP商品获得分成";//分成内容
|
|
|
+ $perMoney = $payMoney*((int)$sysPer/100);//分成收益金额
|
|
|
+ //增加用户收益
|
|
|
+ if($perMoney>0){
|
|
|
+ // return true;//暂时关闭分成
|
|
|
+ (new UserDetailModel)->goodsIncome($proData["uid"],$perMoney,"per_income",$permono,["cash_uid"=>$save["uid"],"p_id"=>$proData["id"],"o_id"=>$o_id]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ $redis->delete($key);
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $redis->delete($ipkey);
|
|
|
+ }
|
|
|
+ return app("json")->success(["order_id"=>$save['order_id'],"money"=>$payMoney,"status"=>$save['status']]);
|
|
|
+ } catch (DbException $db){
|
|
|
+ Db::rollback();
|
|
|
+ if($is_ip_buy==1){
|
|
|
+ $redis->delete($ipkey);
|
|
|
+ }
|
|
|
+ return app('json')->fail("订单生成失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取支付订单详情[第二步]
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function payOrderInfo(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ $data = (new Order)
|
|
|
+ ->field("order_id,total_money,all_money,pay_money,status,time,is_ip_buy")
|
|
|
+ ->where("order_id",$order_id)
|
|
|
+ ->where("uid",$request->user["uid"])
|
|
|
+ ->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail('订单不存在!');
|
|
|
+ }
|
|
|
+ $data=$data->toArray();
|
|
|
+ if($data["status"]==0 && $data["time"]<time()-30*60){
|
|
|
+ (new Order)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
|
|
|
+ $data["status"]==-1;
|
|
|
+ }
|
|
|
+ $data["time"] = date("Y-m-d H:i:s",$data["time"]);
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 生成支付[第三步]
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function orderPay(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ //缓存
|
|
|
+ $redis = \think\facade\Cache::store('redis');
|
|
|
+ $key = 'order_pay_' . $request->user['uid'];
|
|
|
+ $bool = $redis->handler()->exists($key);
|
|
|
+ if ($bool) {
|
|
|
+ return app('json')->fail('请务重复操作,请稍等在重试!');
|
|
|
+ }
|
|
|
+ $redis->set($key,1,6);//6秒缓存
|
|
|
+ $orderData = (new Order)
|
|
|
+ ->where("order_id",$order_id)
|
|
|
+ ->where("uid",$request->user["uid"])
|
|
|
+ ->find();
|
|
|
+ if(empty($orderData)){
|
|
|
+ return app('json')->fail('订单不存在!');
|
|
|
+ }
|
|
|
+ if(empty($request->user['openid'])){
|
|
|
+ return app('json')->fail('用户还未登录001!');
|
|
|
+ }
|
|
|
+ $orderData=$orderData->toArray();
|
|
|
+ if($orderData["status"]>0 || $orderData["pay_money"]<=0){
|
|
|
+ return app('json')->fail('订单已经支付了!');
|
|
|
+ }
|
|
|
+ if($orderData["status"]<0){
|
|
|
+ return app('json')->fail('当前订单不可支付!');
|
|
|
+ }
|
|
|
+ $orderInfoData = (new OrderInfo)->where("o_id",$orderData['id'])->find()->toArray();
|
|
|
+
|
|
|
+ $proData = (new Goods)->where("id",$orderInfoData["p_id"])->find();
|
|
|
+ if(empty($proData) || $proData["status"]!=1){
|
|
|
+ return app('json')->fail('订单中的商品已下架,请重新下单!');
|
|
|
+ }
|
|
|
+ //ip买断验证
|
|
|
+ if($orderData["is_ip_buy"]==1 && (!empty($proData["uip"]) || $proData["is_ip"]==0)){
|
|
|
+ return app('json')->fail('当前商品已经不可买断,请重新下单!');
|
|
|
+ }
|
|
|
+ //清理之前支付凭证 || 防止重复购买
|
|
|
+ $payTrade = (new PayTradeModel)
|
|
|
+ ->where("uid",$request->user["uid"])
|
|
|
+ ->where("o_id",$orderData["id"])
|
|
|
+ ->where("status",0)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $wxpay = new wxpayApi();
|
|
|
+ foreach ($payTrade as $v) {
|
|
|
+ if($v['pay_type'] == 'wxpay') {
|
|
|
+ $result = $wxpay->closeOrder($v['pay_no']);
|
|
|
+ }
|
|
|
+// (new PayTradeModel)->where("pay_no",$v['pay_no'])->delete();
|
|
|
+ }
|
|
|
+ $mtime = microtime(true)*10000;
|
|
|
+ $payOn = "P".date("Ymd").$mtime .rand(1000,9000) . $request->user['uid'];
|
|
|
+ $out_trade_no="";
|
|
|
+ $payMoney = $orderData["pay_money"];
|
|
|
+ $payType=$orderData["pay_type"];
|
|
|
+
|
|
|
+ $give_score=$orderData["give_score"];//赠送积分
|
|
|
+ //添加交易记录
|
|
|
+ $trade = [
|
|
|
+ 'uid' => $request->user['uid'],
|
|
|
+ 'o_id' =>$orderData["id"],
|
|
|
+ 'order_id' =>$orderData["order_id"],
|
|
|
+ 'pay_no' => $payOn,
|
|
|
+ 'out_trade_no' => empty($out_trade_no) ? $payOn : $out_trade_no,
|
|
|
+ 'pay_type' => $payType,
|
|
|
+ 'money' => $payMoney,
|
|
|
+ 'type' => $orderData["is_ip_buy"]==1 ? 'ip' : 'pro',
|
|
|
+ 'd_json' => serialize(['orderId'=>$orderData["order_id"],"give_score"=>$give_score]),
|
|
|
+ 'time' => time(),
|
|
|
+ 'status' => 0,
|
|
|
+ ];
|
|
|
+ $r=(new PayTradeModel)->insert($trade);
|
|
|
+ if(!$r){
|
|
|
+ return app('json')->fail('获取支付信息失败!');
|
|
|
+ }
|
|
|
+ $clictip = get_client_ip();
|
|
|
+ if(empty($clictip)){
|
|
|
+ $clictip = $request->ip();
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $wxpay->wxmpPay([
|
|
|
+ 'description' =>$orderData["is_ip_buy"]==1?"微信小程序商城IP商品买断":"微信小程序商城普通商品购买",
|
|
|
+ 'out_trade_no' => $payOn,
|
|
|
+ 'total' => $payMoney,
|
|
|
+ 'openid' => $request->user['openid'],
|
|
|
+ 'payer_client_ip'=>$clictip,
|
|
|
+ ]);
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail($clictip.$wxpay->errorMsg);
|
|
|
+ }
|
|
|
+ return app('json')->success([
|
|
|
+ 'jsApiParameters'=> $data,
|
|
|
+ 'pay_no' => $payOn,
|
|
|
+ 'order_id' => $orderData["order_id"],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除订单
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function orderDel(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ $data = (new Order)->where("order_id",$order_id)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail('订单不存在!');
|
|
|
+ }
|
|
|
+ if($data["status"]>0){
|
|
|
+ return app('json')->fail('当前订单不可删除!');
|
|
|
+ }
|
|
|
+ (new Order)->where("order_id",$order_id)->where("status","<",1)->where("uid",$request->user["uid"])->delete();
|
|
|
+ return app('json')->success("订单删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清点
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function shopOrderSend(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ $shopData = (new UserShop)->field("id,area, address,name,lx_name,tel,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($shopData)){
|
|
|
+ return app('json')->fail("门店信息错误");
|
|
|
+ }
|
|
|
+ $data = (new Order)->where("order_id",$order_id)->where("shop_id",$shopData["id"])->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail('订单不存在!');
|
|
|
+ }
|
|
|
+ if($data["status"]!=1){
|
|
|
+ return app('json')->fail('当前订单状态不可清点!');
|
|
|
+ }
|
|
|
+ (new Order)->where("order_id",$order_id)->where("status",1)->where("shop_id",$shopData["id"])->update(["status"=>2,"fa_time"=>time()]);
|
|
|
+ //插入记录
|
|
|
+ $saveData=[
|
|
|
+ "o_id"=>$data["id"],
|
|
|
+ "order_id"=>$data["order_id"],
|
|
|
+ "mono"=>"门店确定清点完毕",
|
|
|
+ "time"=>time(),
|
|
|
+ "admin_id"=>0,
|
|
|
+ "admin_name"=>"门店",
|
|
|
+ "type"=>1,
|
|
|
+ "code"=>"shop",
|
|
|
+ ];
|
|
|
+ (new OrderMono)->insert($saveData);
|
|
|
+ return app('json')->success("订单确认清点");
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 提货
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function shopOrderOk(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ $shopData = (new UserShop)->field("id,area, address,name,lx_name,tel,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($shopData)){
|
|
|
+ return app('json')->fail("门店信息错误");
|
|
|
+ }
|
|
|
+ $data = (new Order)->where("order_id",$order_id)->where("shop_id",$shopData["id"])->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail('订单不存在!');
|
|
|
+ }
|
|
|
+ if($data["status"]!=2){
|
|
|
+ return app('json')->fail('当前订单状态不可确认提货!');
|
|
|
+ }
|
|
|
+ (new Order)->where("order_id",$order_id)->where("status",2)->where("shop_id",$shopData["id"])->update(["status"=>3,"ok_time"=>time()]);
|
|
|
+ //插入记录
|
|
|
+ $saveData=[
|
|
|
+ "o_id"=>$data["id"],
|
|
|
+ "order_id"=>$data["order_id"],
|
|
|
+ "mono"=>"门店确定用户已经提走商品",
|
|
|
+ "time"=>time(),
|
|
|
+ "admin_id"=>0,
|
|
|
+ "admin_name"=>"门店",
|
|
|
+ "type"=>1,
|
|
|
+ "code"=>"shop",
|
|
|
+ ];
|
|
|
+ (new OrderMono)->insert($saveData);
|
|
|
+ return app('json')->success("订单确认提货完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认收货
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function orderOk(Request $request){
|
|
|
+ [$order_id] = UtilService::getMore([
|
|
|
+ ['order_id','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ $data = (new Order)->where("order_id",$order_id)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($data)){
|
|
|
+ return app('json')->fail('订单不存在!');
|
|
|
+ }
|
|
|
+ if($data["status"]!=2){
|
|
|
+ return app('json')->fail('当前订单不可确认收货!');
|
|
|
+ }
|
|
|
+ (new Order)->where("order_id",$order_id)->where("status",2)->where("uid",$request->user["uid"])->update(["status"=>3,"ok_time"=>time()]);
|
|
|
+ return app('json')->success("订单确认收货完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function bindPushUip(Request $request){
|
|
|
+ [$pushuip] = UtilService::getMore([
|
|
|
+ ['pushuip','','empty','参数错误'],
|
|
|
+ ],$request,true);
|
|
|
+ //缓存
|
|
|
+ $redis = \think\facade\Cache::store('redis');
|
|
|
+ $key = 'user_parent_bind_' . $request->user['uid'];
|
|
|
+ $bool = $redis->handler()->exists($key);
|
|
|
+ if ($bool) {
|
|
|
+ return app('json')->fail('请务重复操作,请稍等在重试!');
|
|
|
+ }
|
|
|
+ $redis->set($key,1,3);//3秒缓存
|
|
|
+
|
|
|
+ if(!empty($request->user["parent_uid"])){
|
|
|
+ return app('json')->success("绑定成功02");
|
|
|
+ }
|
|
|
+ if($request->user["uip"]==$pushuip){
|
|
|
+ return app('json')->success("绑定成功03");
|
|
|
+ }
|
|
|
+ $parentUser = (new UserModel)->where("uip",$pushuip)->find();
|
|
|
+ if(empty($parentUser)){
|
|
|
+ return app('json')->success("绑定成功04");
|
|
|
+ }
|
|
|
+ if(!empty($parentUser["parent_uid"]) && $parentUser["parent_uid"]==$request->user["uid"]){
|
|
|
+ return app('json')->success("绑定成功05");
|
|
|
+ }
|
|
|
+
|
|
|
+ $r = (new UserModel)->where("uid",$request->user["uid"])->update(["parent_uid"=>$parentUser["uid"],"parent_time"=>time()]);
|
|
|
+ if(!$r){
|
|
|
+ return app('json')->fail('绑定失败!');
|
|
|
+ }
|
|
|
+ return app('json')->success("绑定成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的下级列表
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function branchUserList(Request $request){
|
|
|
+ [$page,$pageSize] = UtilService::getMore([
|
|
|
+ ['page',1],
|
|
|
+ ['pageSize',50],
|
|
|
+ ],$request,true);
|
|
|
+ if($pageSize>50){
|
|
|
+ $pageSize = 50;
|
|
|
+ }
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["parent_uid","=",$request->user['uid']];
|
|
|
+ $where[] = ["status",">",0];
|
|
|
+ $totalCount = (new UserModel)->where($where)->count();
|
|
|
+ $data = (new UserModel)
|
|
|
+ ->field("uip,nickname,avatar,mobile,status,uid")
|
|
|
+ ->where($where)
|
|
|
+ ->order("uid", "desc")
|
|
|
+ ->page((int)$page, (int)$pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $userDetailDb = new UserDetailModel();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["is_mobile"] = empty($v["mobile"])?0:1;
|
|
|
+ $data[$k]["treeIncomeCount"] = $userDetailDb->where("uid",$request->user["uid"])->where("cash_uid",$v["uid"])->where("type",1)->where("code","tree_per_income")->count();
|
|
|
+ $data[$k]["uid"] = null;
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize,'totalCount'=>$totalCount]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 我的活动
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function activityList(Request $request){
|
|
|
+ [$page,$pageSize] = UtilService::getMore([
|
|
|
+ ['page',1],
|
|
|
+ ['pageSize',50],
|
|
|
+ ],$request,true);
|
|
|
+ if($pageSize>50){
|
|
|
+ $pageSize = 50;
|
|
|
+ }
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["d.uid","=",$request->user['uid']];
|
|
|
+ $where[] = ["d.status",">",0];
|
|
|
+ $data = (new ActivityOrder)
|
|
|
+ ->alias("d")
|
|
|
+ ->field("d.id,d.order_id,d.status,d.pay_money,i.imgs,i.title,i.time,i.time_str,i.address")
|
|
|
+ ->join("activity i", "i.id = d.activity_id","left")
|
|
|
+ ->where($where)
|
|
|
+ ->order("d.id", "desc")
|
|
|
+ ->page((int)$page, (int)$pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["time"] = date("Y.m.d",(int)$v["time"]);
|
|
|
+ $data[$k]["img"] = empty($v["imgs"]) ? "" : explode(",", $v["imgs"])[0];
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 活动报名详情
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function activityOrderInfo(Request $request){
|
|
|
+ [$id,$order_id] = UtilService::getMore([
|
|
|
+ ['id',''],
|
|
|
+ ['order_id',''],
|
|
|
+ ],$request,true);
|
|
|
+ if(empty($id) && empty($order_id)){
|
|
|
+ return app('json')->fail("参数错误");
|
|
|
+ }
|
|
|
+ $where=[];
|
|
|
+ $where[]=["uid","=",$request->user["uid"]];
|
|
|
+ if(!empty($id)){
|
|
|
+ $where[]=["id","=",$id];
|
|
|
+ }else{
|
|
|
+ $where[]=["order_id","=",$order_id];
|
|
|
+ }
|
|
|
+ $orderData = (new ActivityOrder)
|
|
|
+ ->alias("d")
|
|
|
+ ->field("d.*,i.imgs,i.title,i.time as activity_time,i.time_str,i.address")
|
|
|
+ ->join("activity i", "i.id = d.activity_id","left")
|
|
|
+ ->where($where)
|
|
|
+ ->find();
|
|
|
+ if(empty($orderData)){
|
|
|
+ return app('json')->fail("报名信息不存在");
|
|
|
+ }
|
|
|
+ $data=$orderData->toArray();
|
|
|
+ if($data["status"]==0 && $data["time"]<time()-30*60){
|
|
|
+ (new ActivityOrder)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
|
|
|
+ $data["status"]==-1;
|
|
|
+ }
|
|
|
+ $data['activity_time'] = empty($data['activity_time'])?"":date('Y-m-d H:i:s',$data['activity_time']);
|
|
|
+ $data['time'] = date('Y.m.d',$data['time']);
|
|
|
+ $data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s',$data['pay_time']);
|
|
|
+ $data['ok_time'] = empty($data['ok_time']) ? '' : date('Y-m-d H:i:s',$data['ok_time']);
|
|
|
+ $data['img'] = empty($data["imgs"])?"": explode(",",$data["imgs"])[0];
|
|
|
+ $data['data'] = empty($data['data'])?[]: unserialize($data['data']);
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取收益明细
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function moneyDetail(Request $request){
|
|
|
+ [$page,$pageSize] = UtilService::getMore([
|
|
|
+ ['page',1],
|
|
|
+ ['pageSize',50],
|
|
|
+ ],$request,true);
|
|
|
+ if($pageSize>50){
|
|
|
+ $pageSize = 50;
|
|
|
+ }
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["d.uid","=",$request->user['uid']];
|
|
|
+ $data = (new UserDetailModel)
|
|
|
+ ->alias("d")
|
|
|
+ ->field("d.*,i.img,i.title as pro_title")
|
|
|
+ ->join("order_info i", "i.o_id = d.o_id","left")
|
|
|
+ ->where($where)
|
|
|
+ ->order("d.id", "desc")
|
|
|
+ ->page((int)$page, (int)$pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
|
|
|
+ $data[$k]["into"] = number_format(floatval($v["into"]),2);
|
|
|
+ if(empty($v["pro_title"])){
|
|
|
+ $data[$k]["pro_title"] = $v["title"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ $money = number_format(floatval($request->user["money"]),2);
|
|
|
+ $money_in = number_format(floatval($request->user["money_in"]),2);
|
|
|
+// $isCheck = false;//关闭提现按钮
|
|
|
+ $isCheck = true;
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize,'money'=>$money,'money_in'=>$money_in,'is_check'=>$isCheck]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取积分明细
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function scoreDetail(Request $request){
|
|
|
+ [$page,$pageSize] = UtilService::getMore([
|
|
|
+ ['page',1],
|
|
|
+ ['pageSize',50],
|
|
|
+ ],$request,true);
|
|
|
+ if($pageSize>50){
|
|
|
+ $pageSize = 50;
|
|
|
+ }
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["d.uid","=",$request->user['uid']];
|
|
|
+ $data = (new UserScoreDetailModel)
|
|
|
+ ->alias("d")
|
|
|
+ ->field("d.*,i.img,i.title as pro_title")
|
|
|
+ ->join("order_info i", "i.o_id = d.o_id","left")
|
|
|
+ ->where($where)
|
|
|
+ ->order("d.id", "desc")
|
|
|
+ ->page((int)$page, (int)$pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ $score = $request->user["score"];
|
|
|
+ $score_in = $request->user["score_in"];
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize,'score'=>$score,'score_in'=>$score_in]);
|
|
|
+ }
|
|
|
+ public function shopOrderList(Request $request){
|
|
|
+ [$page,$pageSize,$type] = UtilService::getMore([
|
|
|
+ ['page',1],
|
|
|
+ ['pageSize',20],
|
|
|
+ ['type','all'],
|
|
|
+ ],$request,true);
|
|
|
+ if($pageSize>50){
|
|
|
+ $pageSize = 50;
|
|
|
+ }
|
|
|
+ $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("is_show",1)->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($shopData)){
|
|
|
+ return app('json')->success(['list' => [], 'pageSize' => $pageSize]);
|
|
|
+ }
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["shop_id","=",$shopData["id"]];
|
|
|
+ //待支付
|
|
|
+ if($type=="pay"){
|
|
|
+ $where[] = ["status","=",0];
|
|
|
+ }
|
|
|
+ //待发货
|
|
|
+ if($type=="send"){
|
|
|
+ $where[] = ["status","=",1];
|
|
|
+ }
|
|
|
+ //待收货
|
|
|
+ if($type=="accept"){
|
|
|
+ $where[] = ["status","=",2];
|
|
|
+ }
|
|
|
+ //已完成
|
|
|
+ if($type=="finish"){
|
|
|
+ $where[] = ["status","=",3];
|
|
|
+ }
|
|
|
+ $data = (new Order)
|
|
|
+ ->where($where)
|
|
|
+ ->order("time", "desc")
|
|
|
+ ->page((int)$page, (int)$pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $orderInfoModel=new OrderInfo();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
|
|
|
+ $data[$k]["pay_time"] = empty($v["pay_time"]) ? "" :date("Y-m-d H:i:s",$v["pay_time"]);
|
|
|
+ $data[$k]["fa_time"] = empty($v["fa_time"]) ? "" :date("Y-m-d H:i:s",$v["fa_time"]);
|
|
|
+ $data[$k]["ok_time"] = empty($v["ok_time"]) ? "" : date("Y-m-d H:i:s",$v["ok_time"]);
|
|
|
+ $data[$k]["info"] = $orderInfoModel->field("id,p_id,img,title,is_ip_buy,price,count")->where("o_id",$v["id"])->where("uid",$request->user["uid"])->select()->toArray();
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 订单列表
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function orderList(Request $request){
|
|
|
+ [$page,$pageSize,$type,$is_ip_buy] = UtilService::getMore([
|
|
|
+ ['page',1],
|
|
|
+ ['pageSize',20],
|
|
|
+ ['type','all'],
|
|
|
+ ['is_ip_buy','']
|
|
|
+ ],$request,true);
|
|
|
+ if($pageSize>50){
|
|
|
+ $pageSize = 50;
|
|
|
+ }
|
|
|
+ //条件
|
|
|
+ $where=[];
|
|
|
+ $where[] = ["uid","=",$request->user['uid']];
|
|
|
+ if(in_array((string)$is_ip_buy,["0","1"])){
|
|
|
+ $where[] = ["is_ip_buy","=",(int)$is_ip_buy];
|
|
|
+ }
|
|
|
+ //待支付
|
|
|
+ if($type=="pay"){
|
|
|
+ $where[] = ["status","=",0];
|
|
|
+ }
|
|
|
+ //待发货
|
|
|
+ if($type=="send"){
|
|
|
+ $where[] = ["status","=",1];
|
|
|
+ }
|
|
|
+ //待收货
|
|
|
+ if($type=="accept"){
|
|
|
+ $where[] = ["status","=",2];
|
|
|
+ }
|
|
|
+ //已完成
|
|
|
+ if($type=="finish"){
|
|
|
+ $where[] = ["status","=",3];
|
|
|
+ }
|
|
|
+ //失效订单
|
|
|
+ if((new Order)->where("uid",$request->user["uid"])->where("status",0)->where("time","<",time()-30*60)->count()>0){
|
|
|
+ (new Order)->where("uid",$request->user["uid"])->where("status",0)->where("time","<",time()-30*60)->update(["status"=>-1]);
|
|
|
+ }
|
|
|
+ $data = (new Order)
|
|
|
+ ->where($where)
|
|
|
+ ->order("time", "desc")
|
|
|
+ ->page((int)$page, (int)$pageSize)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ $orderInfoModel=new OrderInfo();
|
|
|
+ $userDetailDb = new UserDetailModel();
|
|
|
+ foreach($data as $k=>$v){
|
|
|
+ $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
|
|
|
+ $data[$k]["pay_time"] = empty($v["pay_time"]) ? "" :date("Y-m-d H:i:s",$v["pay_time"]);
|
|
|
+ $data[$k]["fa_time"] = empty($v["fa_time"]) ? "" :date("Y-m-d H:i:s",$v["fa_time"]);
|
|
|
+ $data[$k]["ok_time"] = empty($v["ok_time"]) ? "" : date("Y-m-d H:i:s",$v["ok_time"]);
|
|
|
+ $data[$k]["info"] = $orderInfoModel->field("id,p_id,img,title,is_ip_buy,price,count")->where("o_id",$v["id"])->where("uid",$request->user["uid"])->select()->toArray();
|
|
|
+ $data[$k]["ipcount"] = 0;
|
|
|
+ $data[$k]["ipmoney"] = 0;
|
|
|
+ if($v["is_ip_buy"]==1){
|
|
|
+ foreach($data[$k]["info"] as $m=>$n){
|
|
|
+ $totalData = $userDetailDb->field("count(*) as count,sum(`into`) as money")->where("uid",$request->user["uid"])->where("p_id",$n["p_id"])->where("type",1)->find();
|
|
|
+ if(!empty($totalData) && !empty($totalData["count"])){
|
|
|
+ $data[$k]["ipcount"]+=(int)$totalData["count"];
|
|
|
+ $data[$k]["ipmoney"]+=(int)$totalData["money"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $data = empty($data)?[]:$data;
|
|
|
+ return app('json')->success(['list' => $data, 'pageSize' => $pageSize]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单详情
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function orderInfo(Request $request){
|
|
|
+ [$id,$order_id] = UtilService::getMore([
|
|
|
+ ['id',''],
|
|
|
+ ['order_id',''],
|
|
|
+ ],$request,true);
|
|
|
+ if(empty($id) && empty($order_id)){
|
|
|
+ return app('json')->fail("参数错误");
|
|
|
+ }
|
|
|
+ $where=[];
|
|
|
+ $where[]=["uid","=",$request->user["uid"]];
|
|
|
+ if(!empty($id)){
|
|
|
+ $where[]=["id","=",$id];
|
|
|
+ }else{
|
|
|
+ $where[]=["order_id","=",$order_id];
|
|
|
+ }
|
|
|
+ $orderData = (new Order)->where($where)->find();
|
|
|
+ if(empty($orderData)){
|
|
|
+ return app('json')->fail("订单不存在");
|
|
|
+ }
|
|
|
+ $data=$orderData->toArray();
|
|
|
+ $data["shop"]=[
|
|
|
+ "id"=>"",
|
|
|
+ "address"=>"",
|
|
|
+ "name"=>"",
|
|
|
+ "tel"=>""
|
|
|
+ ];
|
|
|
+ if($data["type"]=="shop"){
|
|
|
+ $shopData = (new UserShop)->where("id",$data["shop_id"])->find();
|
|
|
+ if(!empty($shopData)){
|
|
|
+ $data["shop"]["id"] = $shopData["id"];
|
|
|
+ $data["shop"]["address"] = $shopData["area"].$shopData["address"];
|
|
|
+ $data["shop"]["name"] = $shopData["name"];
|
|
|
+ $data["shop"]["tel"] = $shopData["tel"];
|
|
|
+ $data["shop"]["lx_name"] = $shopData["lx_name"];
|
|
|
+ $data["shop"]["longitude"] = $shopData["longitude"];
|
|
|
+ $data["shop"]["latitude"] = $shopData["latitude"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($data["status"]==0 && $data["time"]<time()-30*60){
|
|
|
+ (new Order)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
|
|
|
+ $data["status"]==-1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $data['time'] = date('Y-m-d H:i:s',$orderData['time']);
|
|
|
+ $data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s',$data['pay_time']);
|
|
|
+ $data['fa_time'] = empty($data['fa_time']) ? '' : date('Y-m-d H:i:s',$data['fa_time']);
|
|
|
+ $data['ok_time'] = empty($data['ok_time']) ? '' : date('Y-m-d H:i:s',$data['ok_time']);
|
|
|
+
|
|
|
+ $data['coupon_title']="";
|
|
|
+ if(!empty($data['coupon_id'])) {
|
|
|
+ $couponData = (new UserCouponModel)->where("id",$data['coupon_id'])->find();
|
|
|
+ if(!empty($couponData)) {
|
|
|
+ $data['coupon_title'] = $couponData['title'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+// $tAr['tuiMono'] = '';
|
|
|
+// if(!empty($tAr['isTui'])) {
|
|
|
+// $tAr['tuiMono'] = M('orderMono')->where(['order_id'=>$order['id'],"type"=>0])->order("id desc")->getfield("mono");
|
|
|
+// }
|
|
|
+ $info = (new OrderInfo)->where("o_id",$data["id"])->select();
|
|
|
+ $infoAr = [];
|
|
|
+ foreach ($info as $v2) {
|
|
|
+ $d2['p_id'] = $v2['p_id'];
|
|
|
+ $d2['title'] = $v2['title'];
|
|
|
+ $d2['img'] = $v2['img'];
|
|
|
+ $d2['count'] = $v2['count'];
|
|
|
+ $d2['price'] = $v2['price'];
|
|
|
+ $d2['money'] = $v2['money'];
|
|
|
+ $d2['is_ip_buy'] = $v2['is_ip_buy'];
|
|
|
+ $infoAr[] = $d2;
|
|
|
+ }
|
|
|
+ $data['info'] = $infoAr;
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取门店订单详情
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function shopOrderInfo(Request $request){
|
|
|
+ [$id,$order_id] = UtilService::getMore([
|
|
|
+ ['id',''],
|
|
|
+ ['order_id',''],
|
|
|
+ ],$request,true);
|
|
|
+ if(empty($id) && empty($order_id)){
|
|
|
+ return app('json')->fail("参数错误");
|
|
|
+ }
|
|
|
+ $shopData = (new UserShop)->field("id,area, address,name,tel,lx_name,longitude,latitude")->where("uid",$request->user["uid"])->find();
|
|
|
+ if(empty($shopData)){
|
|
|
+ return app('json')->fail("门店信息错误");
|
|
|
+ }
|
|
|
+ $where=[];
|
|
|
+ $where[]=["shop_id","=",$shopData["id"]];
|
|
|
+ if(!empty($id)){
|
|
|
+ $where[]=["id","=",$id];
|
|
|
+ }else{
|
|
|
+ $where[]=["order_id","=",$order_id];
|
|
|
+ }
|
|
|
+ $orderData = (new Order)->where($where)->find();
|
|
|
+ if(empty($orderData)){
|
|
|
+ return app('json')->fail("订单不存在");
|
|
|
+ }
|
|
|
+ $data=$orderData->toArray();
|
|
|
+ $data["shop"]=[
|
|
|
+ "id"=>"",
|
|
|
+ "address"=>"",
|
|
|
+ "name"=>"",
|
|
|
+ "tel"=>""
|
|
|
+ ];
|
|
|
+ if($data["type"]=="shop"){
|
|
|
+ $shopData = (new UserShop)->where("id",$data["shop_id"])->find();
|
|
|
+ if(!empty($shopData)){
|
|
|
+ $data["shop"]["id"] = $shopData["id"];
|
|
|
+ $data["shop"]["address"] = $shopData["area"].$shopData["address"];
|
|
|
+ $data["shop"]["name"] = $shopData["name"];
|
|
|
+ $data["shop"]["tel"] = $shopData["tel"];
|
|
|
+ $data["shop"]["lx_name"] = $shopData["lx_name"];
|
|
|
+ $data["shop"]["longitude"] = $shopData["longitude"];
|
|
|
+ $data["shop"]["latitude"] = $shopData["latitude"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($data["status"]==0 && $data["time"]<time()-30*60){
|
|
|
+ (new Order)->where("id",$data["id"])->where("uid",$request->user["uid"])->update(["status"=>-1]);
|
|
|
+ $data["status"]==-1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $data['time'] = date('Y-m-d H:i:s',$orderData['time']);
|
|
|
+ $data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s',$data['pay_time']);
|
|
|
+ $data['fa_time'] = empty($data['fa_time']) ? '' : date('Y-m-d H:i:s',$data['fa_time']);
|
|
|
+ $data['ok_time'] = empty($data['ok_time']) ? '' : date('Y-m-d H:i:s',$data['ok_time']);
|
|
|
+
|
|
|
+ $data['coupon_title']="";
|
|
|
+ if(!empty($data['coupon_id'])) {
|
|
|
+ $couponData = (new UserCouponModel)->where("id",$data['coupon_id'])->find();
|
|
|
+ if(!empty($couponData)) {
|
|
|
+ $data['coupon_title'] = $couponData['title'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+// $tAr['tuiMono'] = '';
|
|
|
+// if(!empty($tAr['isTui'])) {
|
|
|
+// $tAr['tuiMono'] = M('orderMono')->where(['order_id'=>$order['id'],"type"=>0])->order("id desc")->getfield("mono");
|
|
|
+// }
|
|
|
+ $info = (new OrderInfo)->where("o_id",$data["id"])->select();
|
|
|
+ $infoAr = [];
|
|
|
+ foreach ($info as $v2) {
|
|
|
+ $d2['p_id'] = $v2['p_id'];
|
|
|
+ $d2['title'] = $v2['title'];
|
|
|
+ $d2['img'] = $v2['img'];
|
|
|
+ $d2['count'] = $v2['count'];
|
|
|
+ $d2['price'] = $v2['price'];
|
|
|
+ $d2['money'] = $v2['money'];
|
|
|
+ $d2['is_ip_buy'] = $v2['is_ip_buy'];
|
|
|
+ $infoAr[] = $d2;
|
|
|
+ }
|
|
|
+ $data['info'] = $infoAr;
|
|
|
+ return app('json')->success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发布圈子
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function upCircle(Request $request){
|
|
|
+ $post = UtilService::getMore([
|
|
|
+ ['id',''],
|
|
|
+ ['title',''],
|
|
|
+ ['content','','empty','请输入动态内容'],
|
|
|
+ ['imgs',[]],
|
|
|
+ ['video',''],
|
|
|
+ ['video_img',''],
|
|
|
+ ['video_time',0],
|
|
|
+ ['pro_id',''],
|
|
|
+ ],$request);
|
|
|
+
|
|
|
+ $post["status"]=0;
|
|
|
+
|
|
|
+ $post["imgs"] = empty($post["imgs"]) ? "" : $post["imgs"];
|
|
|
+ $post["update_time"] = time();
|
|
|
+ if(empty($post["imgs"]) && empty($post["video"])){
|
|
|
+ return app('json')->fail("请至少上传一张主图");
|
|
|
+ }
|
|
|
+ if(!empty($post["imgs"])){
|
|
|
+ $post["video"]="";
|
|
|
+ $post["video_img"]="";
|
|
|
+ $post["video_time"]=0;
|
|
|
+ }
|
|
|
+ if(!empty($post["video"])){
|
|
|
+ $post["imgs"]="";
|
|
|
+ if(empty($post["video_img"])){
|
|
|
+ return app('json')->fail("视频封面错误");
|
|
|
+ }
|
|
|
+ if(empty($post["video_time"]) || (int)$post["video_time"]<=0){
|
|
|
+ return app('json')->fail("视频时长错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!empty($post["pro_id"])){
|
|
|
+ $proData = (new Goods)->where("id",$post["pro_id"])->where("status",1)->find();
|
|
|
+ if(empty($proData)){
|
|
|
+ return app('json')->fail("当前商品不可选中");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $post["pro_id"]=0;
|
|
|
+ }
|
|
|
+ $id = $post["id"];
|
|
|
+ unset($post["id"]);
|
|
|
+ $r=0;
|
|
|
+ if(empty($id) || $id=="0"){
|
|
|
+ $post["time"] = time();
|
|
|
+ $post["uid"] = $request->user["uid"];
|
|
|
+ $r = (new UserCircle)->insert($post);
|
|
|
+ }else{
|
|
|
+ $r = (new UserCircle)->where("id",$id)->update($post);
|
|
|
+ }
|
|
|
+ if($r){
|
|
|
+ return app('json')->success("发布成功,等待客服审核。");
|
|
|
+ }else{
|
|
|
+ return app('json')->fail("数据保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图片上传
|
|
|
+ * @param Request $request
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function upload(Request $request){
|
|
|
+ $sysData = (new SysModel())->where("id",1)->find();
|
|
|
+ $file = $request->file('file');
|
|
|
+ $code = $request->post("code","image");
|
|
|
+ if(empty($file)) {
|
|
|
+ return app('json')->fail("未上传文件");
|
|
|
+ }
|
|
|
+ if(!in_array($code, ["video","image","circle","advert","goods","activity"])){
|
|
|
+ return app('json')->fail("上传路径错误");
|
|
|
+ }
|
|
|
+ $ext = $file->extension();
|
|
|
+ if(!in_array($ext, array("png","jpeg","gif","jpg"))){
|
|
|
+ return app('json')->fail("图片类型错误");
|
|
|
+ }
|
|
|
+ $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
|
|
|
+ if(!$upPath){
|
|
|
+ return app('json')->fail("图片上传失败01");
|
|
|
+ }
|
|
|
+ $savePath = $sysData['system_url'].'/resource/' . $upPath;
|
|
|
+ $imgUrl = str_replace("\\", "/", $savePath);
|
|
|
+ return app('json')->success(['img'=>$imgUrl]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 视频上传
|
|
|
+ * @param Request $request
|
|
|
+ * @return type
|
|
|
+ */
|
|
|
+ public function uploadVideo(Request $request){
|
|
|
+ $sysData = (new SysModel())->where("id",1)->find();
|
|
|
+ $file = $request->file('file');
|
|
|
+ $code = $request->post("code","video");
|
|
|
+ if(empty($file)) {
|
|
|
+ return app('json')->fail("未上传文件");
|
|
|
+ }
|
|
|
+ if(!in_array($code, ["video"])){
|
|
|
+ return app('json')->fail("上传路径错误");
|
|
|
+ }
|
|
|
+ $ext = $file->extension();
|
|
|
+ if(!in_array($ext, array("mp4","megp4"))){
|
|
|
+ return app('json')->fail("视频类型错误");
|
|
|
+ }
|
|
|
+ $upPath = \think\facade\Filesystem::disk('resource')->putFile( $code, $file);
|
|
|
+ if(!$upPath){
|
|
|
+ return app('json')->fail("上传失败01");
|
|
|
+ }
|
|
|
+ $savePath = $sysData['system_url'].'/resource/' . $upPath;
|
|
|
+ $imgUrl = str_replace("\\", "/", $savePath);
|
|
|
+ return app('json')->success(['video'=>$imgUrl]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 钻币明细
|
|
|
+ * @param Request $request
|
|
|
+ */
|
|
|
+ public function scoreList(Request $request)
|
|
|
+ {
|
|
|
+ $pageSize = 10;
|
|
|
+ [$page, $type, $monthTime]
|
|
|
+ = UtilService::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ['type',0],
|
|
|
+ ['monthTime', ''],
|
|
|
+ ], $request, true);
|
|
|
+ $data = (new UserScoreDetail)
|
|
|
+ ->where("uid", $request->user['uid'])
|
|
|
+ ->when($type!=0, function ($query) use ($type) {
|
|
|
+ if($type==1){
|
|
|
+ $query->where("type", 1);
|
|
|
+ }
|
|
|
+ if($type==-1){
|
|
|
+ $query->where("type", -1);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->when(!empty($monthTime), function ($query) use ($monthTime) {
|
|
|
+ $query->whereMonth("time", $monthTime);
|
|
|
+ })
|
|
|
+ ->order("id", "desc")
|
|
|
+ ->page((int)$page, $pageSize)
|
|
|
+ ->select();
|
|
|
+ $tAr = UtilService::getParam([
|
|
|
+ 'id',
|
|
|
+ 'title',
|
|
|
+ 'content',
|
|
|
+ 'type',
|
|
|
+ ['into','v',function($item){
|
|
|
+ return floatval($item);
|
|
|
+ }],
|
|
|
+ ['time', 'time', 'date("Y-m-d H:i:s",$1)'],
|
|
|
+ ], $data);
|
|
|
+ return app('json')->success(['list' => $tAr, 'pageSize' => $pageSize]);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|