init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
namespace SmallProgramApi\Controller;
|
||||
|
||||
//[1.8.77]
|
||||
|
||||
use Common\Business\Plug;
|
||||
use Common\Model\RetailCouponLogsModel;
|
||||
use Common\Model\RetailPlusSetModel;
|
||||
use Common\Model\RetailSmallProgramUserModel;
|
||||
use Common\Model\RetailVipIntegralModel;
|
||||
use Common\Model\RetailVipMCouponModel;
|
||||
use Common\Model\RetailVipModel;
|
||||
use Common\Model\WxappinfoModel;
|
||||
use Common\Model\RetailMessageModel;
|
||||
use Common\Model\BillOrderViewModel;
|
||||
|
||||
use Common\Model\RetailStoreModel;
|
||||
|
||||
|
||||
use mysql_xdevapi\Exception;
|
||||
use PayCoupon\Model\PayCouponRecordModel;
|
||||
use ShopCoupon\Model\ShopCouponRecordModel;
|
||||
use Think\Hook;
|
||||
|
||||
class MyController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 用户信息plus会员
|
||||
*/
|
||||
public function myShow()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$uid = self::$uid;
|
||||
$store_id = self::$store_id;
|
||||
$merchant_id = self::$merchant_id;
|
||||
$SPUModel = D('RetailSmallProgramUser');
|
||||
$where[$SPUModel::ID] = $uid;
|
||||
$my_info = $SPUModel->getFind($where);
|
||||
if ($my_info) {
|
||||
$CouponLogsModel = D('RetailCouponLogs');
|
||||
$coupon = $CouponLogsModel->getCount(array($CouponLogsModel::UID => $uid, $CouponLogsModel::STATUS => 1, $CouponLogsModel::STORE_ID => $store_id));
|
||||
$my_info['is_vip'] = 0;
|
||||
if (!empty($my_info[$SPUModel::VID])) {
|
||||
$VipModel = D('RetailVip');
|
||||
$vip = $VipModel->getFind(array($VipModel::ID => $my_info[$SPUModel::VID]), array($VipModel::INTEGRAL, $VipModel::BALANCE, $VipModel::STATUS, $VipModel::OPEN_ID));
|
||||
if (!empty($vip)) {
|
||||
$my_info[$VipModel::INTEGRAL] = $vip[$VipModel::INTEGRAL] ? $vip[$VipModel::INTEGRAL] : 0.00;
|
||||
$my_info[$VipModel::BALANCE] = $vip[$VipModel::BALANCE] ? $vip[$VipModel::BALANCE] : 0.00;
|
||||
$my_info['is_vip'] = 1;
|
||||
$my_info['openid'] = $vip[$VipModel::OPEN_ID];
|
||||
}
|
||||
}
|
||||
$my_info['count'] = $coupon;
|
||||
$res['status'] = 1;
|
||||
$res['my_info'] = $my_info;
|
||||
$redis_key = 'retail_*_*_*_' . $uid . '_*';
|
||||
$res['wait_pay_num'] = $this->getWaitPayOrderNum($redis_key);
|
||||
$PlusSetModel = D('RetailPlusSet');
|
||||
$plus_set = $PlusSetModel->getFind(array($PlusSetModel::MERCHANT_ID => $merchant_id, $PlusSetModel::SWITCH_TYPE => 2));
|
||||
$res['open_plus'] = $plus_set ? 1 : 0;
|
||||
// $TurntableModel = D('Turntable');
|
||||
// $this_time = time();
|
||||
// $map = array(
|
||||
// 'merchant_id' => $merchant_id,
|
||||
// 'status' => 1,
|
||||
// 'start_time' => array('elt', $this_time),
|
||||
// 'end_time' => array('gt', $this_time),
|
||||
// 'turntable_type' => 5,
|
||||
// );
|
||||
// $res['open_turntable_task'] = $TurntableModel->getCount($map);
|
||||
} else {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '未找到此用户';
|
||||
}
|
||||
} else {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '网络错误';
|
||||
}
|
||||
$this->ajaxReturn($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
public function myShow_v1()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$uid = self::$uid;
|
||||
$merchant_id = self::$merchant_id;
|
||||
$SPUModel = new RetailSmallProgramUserModel();
|
||||
$map = array(
|
||||
'id' => $uid,
|
||||
);
|
||||
$user_info = $SPUModel->getFind($map);
|
||||
if ($user_info && $user_info['login_state'] == 1) {
|
||||
$time = time();
|
||||
$CouponLogsModel = new RetailCouponLogsModel();
|
||||
$map = array(
|
||||
'l.uid' => $uid,
|
||||
'l.status' => 1,
|
||||
'c.end_time' => ['gt', $time], //结束时间大于当前时间
|
||||
);
|
||||
//普通优惠券
|
||||
$coupon = $CouponLogsModel->getCouponCount($map);
|
||||
$user_info['is_vip'] = 0;
|
||||
if (!empty($user_info['vid'])) {
|
||||
$VipModel = new RetailVipModel();
|
||||
$map = array(
|
||||
'id' => $user_info['vid']
|
||||
);
|
||||
$vip = $VipModel->getFind($map, ['integral', 'balance', 'status', 'openid', 'plus_type', 'grade_integral']);
|
||||
if (!empty($vip)) {
|
||||
$user_info['integral'] = $vip['integral'] ? $vip['integral'] : 0.00;
|
||||
$user_info['balance'] = $vip['balance'] ? $vip['balance'] : 0.00;
|
||||
$user_info['is_vip'] = 1;
|
||||
$user_info['openid'] = $vip['openid'];
|
||||
$user_info['plus_type'] = $vip['plus_type'];
|
||||
}
|
||||
//会员优惠券数量
|
||||
$VipMCouponModel = new RetailVipMCouponModel();
|
||||
$vip_coupon = $VipMCouponModel->getGrantRecordCount([
|
||||
'r.vid' => $user_info['vid'],
|
||||
'r.isuse' => 1,
|
||||
[
|
||||
[
|
||||
'c.coupontype' => 1,
|
||||
'c.endtime' => ['gt', $time]
|
||||
],
|
||||
[
|
||||
'c.coupontype' => 2,
|
||||
'r.addtime + (c.daynum*86400)' => ['gt', $time]
|
||||
],
|
||||
[
|
||||
'c.coupontype' => 3,
|
||||
'r.addtime+86400' => ['lt', $time],
|
||||
'r.addtime+86400+(c.daynum*86400)' => ['gt', $time]
|
||||
|
||||
],
|
||||
'_logic' => 'OR'
|
||||
]
|
||||
]);
|
||||
$coupon += $vip_coupon;
|
||||
}
|
||||
$Plug = new Plug();
|
||||
$plugResult = $Plug->PlugPermissions([
|
||||
'merchant_id' => $merchant_id,
|
||||
'identification_arr' => [
|
||||
'wxpaycoupon',
|
||||
'shopcoupon'
|
||||
]
|
||||
]);
|
||||
if (!empty($plugResult['data']['plug']['wxpaycoupon'])) {
|
||||
//代金券可使用
|
||||
try {
|
||||
$PayCouponRecordModel = new PayCouponRecordModel();
|
||||
$pay_coupon_count = $PayCouponRecordModel->recordCount([
|
||||
'r.merchant_id' => $merchant_id,
|
||||
'r.uid' => $uid,
|
||||
'r.use_status' => 1,
|
||||
'p.available_end_time' => ['gt', time()]
|
||||
]);
|
||||
$coupon += $pay_coupon_count ? $pay_coupon_count : 0;
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
if (!empty($plugResult['data']['plug']['shopcoupon'])) {
|
||||
//商家券可使用
|
||||
try {
|
||||
$ShopCouponRecordModel = new ShopCouponRecordModel();
|
||||
$shop_coupon_count = $ShopCouponRecordModel->recordCount([
|
||||
'r.merchant_id' => $merchant_id,
|
||||
'r.xcx_id' => $uid,
|
||||
'r.used_type' => 1,
|
||||
'c.available_end_time' => ['gt', time()]
|
||||
]);
|
||||
$coupon += $shop_coupon_count ? $shop_coupon_count : 0;
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$user_info['count'] = round($coupon);
|
||||
$redis_key = 'retail_*_*_*_' . $uid . '_*';
|
||||
$PlusSetModel = new RetailPlusSetModel();
|
||||
$map = array(
|
||||
$PlusSetModel::MERCHANT_ID => $merchant_id,
|
||||
$PlusSetModel::SWITCH_TYPE => 2
|
||||
);
|
||||
$plus_set = $PlusSetModel->getFind($map);
|
||||
|
||||
$VipGradeModel = new RetailVipIntegralModel(); //会员等级模型
|
||||
$grade = $VipGradeModel->getVipGradeInfo($merchant_id, $vip['grade_integral']);
|
||||
if (empty($grade['grade_name'])) {
|
||||
$grade['grade_name'] = '常规会员';
|
||||
}
|
||||
$user_info['grade_name'] = $grade['grade_name'];
|
||||
|
||||
// 分销员身份判断
|
||||
Hook::listen('user_distributor', $distributor);
|
||||
$user_info['distributor'] = $distributor;
|
||||
|
||||
// 获取未读消息数量
|
||||
$MessageModel = new RetailMessageModel();
|
||||
$user_info['unread_message'] = $MessageModel->getCount(['uid' => $uid, 'state' => 0]);
|
||||
|
||||
$WxAppInfoModel = new WxappinfoModel();
|
||||
$online_status = $WxAppInfoModel->getFindField(array('merchant_id' => $merchant_id), 'online_status');
|
||||
|
||||
// 获取各个订单状态
|
||||
$BillOrderViewModel = new BillOrderViewModel();
|
||||
|
||||
$order_status['wait_pay_num'] = $this->getWaitPayOrderNum_v1($redis_key); // 待付款
|
||||
$order_status['wait_delivery'] = $BillOrderViewModel->getCount(['status' => 1, 'order_type' => 1, 'uid' => $uid, 'refund_status' => 0]); // 待发货/自取
|
||||
$order_status['wait_take'] = $BillOrderViewModel->getCount(['status' => 2, 'order_type' => 1, 'uid' => $uid, 'refund_status' => 0, 'pickup_type' => ['in', '2,3']]); // 待收货
|
||||
$order_status['wait_evaluation'] = $BillOrderViewModel->getCount(['status' => 3, 'order_type' => 1, 'uid' => $uid, 'refund_status' => 0, 'eval_status' => 0]); // 待评价
|
||||
$sales_map = [
|
||||
'uid' => $uid,
|
||||
'refund_status' => ['in', '1,3,4,5'],
|
||||
'order_type' => ['in', '2,3']
|
||||
];
|
||||
$order_status['after_sales'] = $BillOrderViewModel->getCount($sales_map); // 售后
|
||||
|
||||
$open_distribution = array('merchant_id' => $merchant_id);
|
||||
\Think\Hook::listen('open_distribution', $open_distribution); //检查商家是否开启分销
|
||||
|
||||
if ($user_info && $user_info['store_id']) {
|
||||
$storeModel = new RetailStoreModel();
|
||||
$whereName = [
|
||||
'id' => $user_info['store_id']
|
||||
];
|
||||
$whereField = 'storetag';
|
||||
$user_info['store_name'] = $storeModel->getFindField($whereName, $whereField);
|
||||
} else {
|
||||
$user_info['store_name'] = '';
|
||||
}
|
||||
|
||||
$res = array(
|
||||
'status' => 1,
|
||||
'msg' => '数据获取成功',
|
||||
'my_info' => $user_info,
|
||||
'wait_pay_num' => $this->getWaitPayOrderNum_v1($redis_key),
|
||||
'open_plus' => $plus_set ? 1 : 0,
|
||||
'online_status' => $online_status,
|
||||
'order_status' => $order_status,
|
||||
'open_distribution' => $open_distribution['is_open'] == 1 ? 1 : 0,
|
||||
);
|
||||
} else {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '用户未登录';
|
||||
}
|
||||
} else {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '网络错误';
|
||||
}
|
||||
$this->ajaxReturn($res);
|
||||
}
|
||||
|
||||
/*
|
||||
*获取商户是否开启礼品卡
|
||||
*/
|
||||
public function merchantGift()
|
||||
{
|
||||
$uid = self::$uid;
|
||||
$merchant_id = self::$merchant_id;
|
||||
if (empty($uid) || empty($merchant_id)) {
|
||||
$result['status'] = 0;
|
||||
$result['msg'] = '缺少参数';
|
||||
$this->ajaxReturn($result);
|
||||
}
|
||||
$GiftCardModel = D('RetailGiftCard');
|
||||
$Gift = $GiftCardModel->getFind(array($GiftCardModel::MERCHANT_ID => $merchant_id));
|
||||
if (!empty($Gift)) {
|
||||
$result['status'] = 1;
|
||||
$result['msg'] = '查询成功';
|
||||
} else {
|
||||
$result['status'] = 0;
|
||||
$result['msg'] = '商家未开启礼品卡';
|
||||
}
|
||||
$this->ajaxReturn($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否获取到服务商或者公众号的openid
|
||||
*/
|
||||
public function getServiceOpenid()
|
||||
{
|
||||
$xcxUserModel = new RetailSmallProgramUserModel();
|
||||
$xcxInfo = $xcxUserModel->getFind([
|
||||
'id' => self::$uid
|
||||
], "service_openid,ordinary_openid");
|
||||
if (empty($xcxInfo['ordinary_openid'])) {
|
||||
$ordinary_status = 1; //普通模式
|
||||
}
|
||||
if (empty($xcxInfo['service_openid'])) {
|
||||
$service_status = 2; //服务商模式
|
||||
}
|
||||
$this->ajaxReturn([
|
||||
'status' => 1,
|
||||
'message' => '查询成功',
|
||||
'data' => [
|
||||
'ordinary_status' => $ordinary_status ? $ordinary_status : '',
|
||||
'service_status' => $service_status ? $service_status : '',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function setName()
|
||||
{
|
||||
$merchant_id = I('post.merchant_id'); //商户id
|
||||
$nickname = I('post.nickname'); //用户昵称
|
||||
$openid = I('post.openid'); //用户openid
|
||||
if (empty($merchant_id) || empty($nickname) || empty($openid)) {
|
||||
$result['status'] = 0;
|
||||
$result['msg'] = '缺少参数';
|
||||
$this->ajaxReturn($result);
|
||||
}
|
||||
$SmallProgramUserModel = D('RetailSmallProgramUser');
|
||||
$map = array(
|
||||
$SmallProgramUserModel::OPENID => $openid,
|
||||
$SmallProgramUserModel::MERCHANT_ID => $merchant_id
|
||||
);
|
||||
$SmallProgramUserModel->updateOrder($map, array(
|
||||
$SmallProgramUserModel::NICKNAME => $nickname,
|
||||
$SmallProgramUserModel::LINK_NAME => $nickname,
|
||||
));
|
||||
$result['status'] = 1;
|
||||
$result['msg'] = '更新成功';
|
||||
$this->ajaxReturn($result);
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户