初始化代码
This commit is contained in:
263
app/farm/controller/IndexBalance.php
Normal file
263
app/farm/controller/IndexBalance.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
namespace app\farm\controller;
|
||||
use app\ApiRest;
|
||||
|
||||
use app\farm\model\BalanceCard;
|
||||
use app\farm\model\BalanceOrder;
|
||||
use app\farm\model\BalanceWater;
|
||||
|
||||
use app\farm\model\User;
|
||||
use app\Rest;
|
||||
|
||||
|
||||
use app\shop\controller\IndexWxPay;
|
||||
use longbingcore\wxcore\PayModel;
|
||||
use think\App;
|
||||
|
||||
use think\Request;
|
||||
|
||||
|
||||
|
||||
class IndexBalance extends ApiRest
|
||||
{
|
||||
|
||||
protected $model;
|
||||
|
||||
protected $article_model;
|
||||
|
||||
protected $coach_model;
|
||||
|
||||
protected $water_model;
|
||||
|
||||
protected $app;
|
||||
|
||||
|
||||
public function __construct(App $app) {
|
||||
|
||||
parent::__construct($app);
|
||||
|
||||
$this->app = $app;
|
||||
|
||||
$this->model = new BalanceCard();
|
||||
|
||||
$this->balance_order = new BalanceOrder();
|
||||
|
||||
$this->water_model = new BalanceWater();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-04 19:09
|
||||
* @功能说明:储值充值卡列表
|
||||
*/
|
||||
public function cardList(){
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['uniacid','=',$this->_uniacid];
|
||||
|
||||
$dis[] = ['status','=',1];
|
||||
|
||||
if(!empty($input['name'])){
|
||||
|
||||
$dis[] = ['title','like','%'.$input['name'].'%'];
|
||||
|
||||
}
|
||||
|
||||
$data = $this->model->dataList($dis,$input['limit']);
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-07 17:00
|
||||
* @功能说明:充值余额
|
||||
*/
|
||||
public function payBalanceOrder(){
|
||||
|
||||
$input = $this->_input;
|
||||
|
||||
if(!empty($input['card_id'])){
|
||||
|
||||
$dis = [
|
||||
|
||||
'id' => $input['card_id'],
|
||||
|
||||
'status' => 1
|
||||
];
|
||||
|
||||
$card = $this->model->dataInfo($dis);
|
||||
|
||||
if(empty($card)){
|
||||
|
||||
$this->errorMsg('充值卡已被下架');
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$card = [
|
||||
|
||||
'price' => $input['price'],
|
||||
|
||||
'true_price' => $input['price'],
|
||||
|
||||
'id' => 0,
|
||||
|
||||
'integral' => 0,
|
||||
|
||||
'member_level'=> 0,
|
||||
|
||||
'title' => '自定义金额充值'
|
||||
];
|
||||
}
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $this->_uniacid,
|
||||
|
||||
'user_id' => $this->getUserId(),
|
||||
|
||||
'order_code' => orderCode(),
|
||||
|
||||
'pay_price' => $card['price'],
|
||||
|
||||
'sale_price' => $card['price'],
|
||||
|
||||
'true_price' => $card['true_price'],
|
||||
|
||||
'card_id' => $card['id'],
|
||||
|
||||
'title' => $card['title'],
|
||||
|
||||
'integral' => $card['integral'],
|
||||
|
||||
'pay_model' => $input['pay_model'],
|
||||
|
||||
'member_level'=> $card['member_level'],
|
||||
//
|
||||
// 'phone' => $input['phone']
|
||||
|
||||
];
|
||||
|
||||
$res = $this->balance_order->dataAdd($insert);
|
||||
|
||||
if($res==0){
|
||||
|
||||
$this->errorMsg('充值失败');
|
||||
|
||||
}
|
||||
|
||||
if($input['pay_model']==3){
|
||||
|
||||
$pay_model = new PayModel($this->payConfig());
|
||||
|
||||
$jsApiParameters = $pay_model->aliPay($insert['order_code'],$insert['pay_price'],'余额充值');
|
||||
|
||||
$arr['pay_list']= $jsApiParameters;
|
||||
|
||||
$arr['order_code']= $insert['order_code'];
|
||||
|
||||
}else{
|
||||
//微信支付
|
||||
$pay_controller = new IndexWxPay($this->app);
|
||||
//支付
|
||||
$jsApiParameters= $pay_controller->createWeixinPay($this->payConfig(),$this->getUserInfo()['openid'],$this->_uniacid,"储值",['type' => 'Balance' , 'out_trade_no' => $insert['order_code']],$insert['pay_price']);
|
||||
|
||||
$arr['pay_list']= $jsApiParameters;
|
||||
}
|
||||
|
||||
return $this->success($arr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-07 17:34
|
||||
* @功能说明:充值订单列表
|
||||
*/
|
||||
public function balaceOrder(){
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['status','=',2];
|
||||
|
||||
$dis[] = ['user_id','=',$this->getUserId()];
|
||||
|
||||
if(!empty($input['start_time'])){
|
||||
|
||||
$dis[] = ['pay_time','between',"{$input['start_time']},{$input['end_time']}"];
|
||||
|
||||
}
|
||||
|
||||
$data = $this->balance_order->dataList($dis);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
|
||||
$v['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-07-07 18:00
|
||||
* @功能说明:消费明细
|
||||
*/
|
||||
public function payWater(){
|
||||
|
||||
$input = $this->_param;
|
||||
|
||||
$dis[] = ['user_id','=',$this->getUserId()];
|
||||
|
||||
// $dis[] = ['type','=',2];
|
||||
|
||||
if(!empty($input['start_time'])){
|
||||
|
||||
$dis[] = ['create_time','between',"{$input['start_time']},{$input['end_time']}"];
|
||||
|
||||
}
|
||||
|
||||
$data = $this->water_model->dataList($dis);
|
||||
|
||||
if(!empty($data['data'])){
|
||||
|
||||
foreach ($data['data'] as &$v){
|
||||
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user