329 行
9.1 KiB
PHP
可执行文件
329 行
9.1 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace PayCoupon\Controller;
|
|
|
|
use Addons\Pay\WxPayV3;
|
|
use Common\Business\DownFile;
|
|
use Common\Business\Goods;
|
|
use Common\Business\GoodsClassify;
|
|
use Common\Business\PayUser;
|
|
use Common\Business\Store;
|
|
use Common\Business\XcxUser;
|
|
use Common\Model\RetailPaySetModel;
|
|
use PayCoupon\Business\PayCoupon;
|
|
use PayCoupon\Business\PayCouponRecord;
|
|
use PayCoupon\Model\PayCouponModel;
|
|
use Retail\Controller\BaseController;
|
|
|
|
/**
|
|
* 支付券控制器
|
|
* Class IndexController
|
|
* @package PayCoupon\Controller
|
|
*/
|
|
class IndexController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$arr = [
|
|
'search' => '/index.php/PayCoupon/Index/index',
|
|
'coupon' => '/index.php/PayCoupon/Index/createCoupon',
|
|
'coupon_info' => '/index.php/PayCoupon/Index/couponInfo',
|
|
'activation' => '/index.php/PayCoupon/Index/activation',
|
|
'suspendOperation' => '/index.php/PayCoupon/Index/suspendOperation',
|
|
'deleteOperation' => '/index.php/PayCoupon/Index/deleteOperation',
|
|
'grant' => '/index.php/PayCoupon/Index/userList',
|
|
'grantAction' => '/index.php/PayCoupon/Index/grant',
|
|
'getRecord' => '/index.php/PayCoupon/Index/record',
|
|
'download' => '/index.php/PayCoupon/Index/record',
|
|
];
|
|
$authArr = checkFunction($arr);
|
|
$paySetModel = new RetailPaySetModel();
|
|
$paySet = $paySetModel->getFindMerchantPaySet($this->merchant_id);
|
|
if(!empty($paySet['config']['xcx_sub_mchid']) && !empty($paySet['config']['systemConfig']['mch_id']) && !empty($paySet['config']['systemConfig']['wx_serial_no']) && !empty($paySet['config']['systemConfig']['wx_apiclient_key']) && !empty($paySet['config']['systemConfig']['wx_appid'])){
|
|
$pay_type = 2;
|
|
}else{
|
|
$pay_type = 1;
|
|
}
|
|
$this->assign('auth', $authArr);
|
|
$this->assign('pay_type', $pay_type);
|
|
$this->display();
|
|
}
|
|
|
|
|
|
/**
|
|
* 门店商品列表
|
|
*/
|
|
public function storeGoodsList()
|
|
{
|
|
$data = I('post.');
|
|
$goodsClass = new Goods();
|
|
$result = $goodsClass->getStoreGoodsList($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 顶级分类
|
|
*/
|
|
public function getGoodsClass1()
|
|
{
|
|
$goodsClass = new GoodsClassify();
|
|
$result = $goodsClass->getGoodsClassTopLevel($this->merchant_id);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 门店列表
|
|
*/
|
|
public function store()
|
|
{
|
|
$storeClass = new Store();
|
|
$store = $storeClass->getStoreList(['merchant_id' => $this->merchant_id]);
|
|
$this->ajaxReturn(['data' => ['store' => $store]]);
|
|
}
|
|
|
|
|
|
/**
|
|
* 代金券列表
|
|
*/
|
|
public function CouponList()
|
|
{
|
|
$data = I('post.');
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$couponClass = new PayCouponRecord();
|
|
$result = $couponClass->getCouponList($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/**
|
|
* 上传Logo
|
|
*/
|
|
public function uploadWx()
|
|
{
|
|
$payCouponClass = new PayCoupon();
|
|
$result = $payCouponClass->wxUpload(['merchant_id' => $this->merchant_id]);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 代金券创建
|
|
*/
|
|
public function createCoupon()
|
|
{
|
|
$data = json_decode(I('post.')['add_form'], true);
|
|
$param = [
|
|
'merchant_id' => $this->merchant_id,
|
|
'data' => $data,
|
|
'operator_id' => session("jurisdiction_user")['id'] //操作人id
|
|
];
|
|
$PayCouponClass = new PayCoupon();
|
|
$result = $PayCouponClass->createCoupon($param);
|
|
if ($result['status'] == 1) {
|
|
$param = [
|
|
'source' => 0,
|
|
'type' => 3,
|
|
'request_data' => json_encode($_POST),
|
|
'desc' => '创建代金券'
|
|
];
|
|
action_log_v2($param);
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 代金券详情
|
|
*/
|
|
public function couponInfo()
|
|
{
|
|
$id = I("post.id");
|
|
$payCouponClass = new PayCouponRecord();
|
|
$result = $payCouponClass->couponInfo([
|
|
'id' => $id,
|
|
'merchant_id' => $this->merchant_id
|
|
]);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 激活代金券
|
|
*/
|
|
public function activation()
|
|
{
|
|
$id = I("post.id");
|
|
$payCouponClass = new PayCoupon();
|
|
$result = $payCouponClass->couponActivation([
|
|
'id' => $id,
|
|
'merchant_id' => $this->merchant_id
|
|
]);
|
|
if ($result['status'] == 1) {
|
|
$param = [
|
|
'source' => 0,
|
|
'type' => 3,
|
|
'request_data' => json_encode($_POST),
|
|
'desc' => '激活代金券'
|
|
];
|
|
action_log_v2($param);
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 用户列表
|
|
*/
|
|
public function userList()
|
|
{
|
|
$data = I("post.");
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
switch ($data['create_coupon_type']) {
|
|
case 1:
|
|
//普通模式
|
|
switch ($data['create_source_type']) {
|
|
case 1:
|
|
//小程序
|
|
$data['type'] = 1;
|
|
break;
|
|
case 2:
|
|
//公众号
|
|
$data['type'] = 2;
|
|
break;
|
|
}
|
|
break;
|
|
case 2:
|
|
//服务商模式
|
|
$data['type'] = 3;
|
|
break;
|
|
}
|
|
$xcxUserClass = new XcxUser();
|
|
$result = $xcxUserClass->getXcxUserList($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 发放代金券
|
|
*/
|
|
public function grant()
|
|
{
|
|
$data = I("post.");
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$data['operator_id'] = session("jurisdiction_user")['id']; //操作人id
|
|
$payCouponClass = new PayCoupon();
|
|
$result = $payCouponClass->grantCoupon($data);
|
|
if ($result['status'] == 1) {
|
|
$param = [
|
|
'source' => 0,
|
|
'type' => 3,
|
|
'request_data' => json_encode($_POST),
|
|
'desc' => '发放代金券'
|
|
];
|
|
action_log_v2($param);
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 发放记录
|
|
*/
|
|
public function record()
|
|
{
|
|
$data = I("post.");
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$payCouponClass = new PayCouponRecord();
|
|
$result = $payCouponClass->getRecord($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 暂停重启代金券
|
|
*/
|
|
public function suspendOperation()
|
|
{
|
|
$data = I("post.");
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$payCouponClass = new PayCoupon();
|
|
$result = $payCouponClass->suspendRestart($data);
|
|
if ($result['status'] == 1) {
|
|
switch ($data['operation_type']) {
|
|
case 1:
|
|
$desc = '暂停代金券';
|
|
break;
|
|
case 2:
|
|
$desc = '重启代金券';
|
|
break;
|
|
}
|
|
$param = [
|
|
'source' => 0,
|
|
'type' => 3,
|
|
'request_data' => json_encode($_POST),
|
|
'desc' => $desc
|
|
];
|
|
action_log_v2($param);
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 删除代金券
|
|
*/
|
|
public function deleteOperation()
|
|
{
|
|
$id = I('post.id');
|
|
if (empty($id)) {
|
|
$this->ajaxReturn([
|
|
'status' => 0,
|
|
'message' => '缺少参数'
|
|
]);
|
|
}
|
|
$payCouponModel = new PayCouponModel();
|
|
$result = $payCouponModel->updateOrder([
|
|
'id' => $id
|
|
], [
|
|
'status' => 2
|
|
]);
|
|
if (!empty($result)) {
|
|
$param = [
|
|
'source' => 0,
|
|
'type' => 3,
|
|
'request_data' => json_encode($_POST),
|
|
'desc' => '删除代金券'
|
|
];
|
|
action_log_v2($param);
|
|
$result = callBack(statusCode()['success'], "操作成功");
|
|
} else {
|
|
$result = callBack(statusCode()['success'], "操作失败");
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
//下载券码
|
|
public function downloadCoupon()
|
|
{
|
|
ini_set('memory_limit', -1);
|
|
$data = I('post.');
|
|
$data['merchant_id'] = $this->merchant_id;
|
|
$ShopCouponClass = new PayCoupon();
|
|
$result = $ShopCouponClass->downloadCouponCode($data);
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
//下载券码压缩包
|
|
public function downloadCouponZip()
|
|
{
|
|
ini_set('memory_limit', -1);
|
|
$data = I('get.');
|
|
$data['zip_name'] = 'djq';
|
|
$data['file_type'] = 'jpg';
|
|
$data['store_arr'] = json_decode($data['store_arr'], true);
|
|
$data['file_name_arr'] = json_decode($data['coupon_arr'], true);
|
|
$DownFileClass = new DownFile();
|
|
$DownFileClass->downloadZip($data);
|
|
}
|
|
} |