|
@@ -3,21 +3,17 @@
|
|
namespace Modules\Channel\Http\Controllers;
|
|
namespace Modules\Channel\Http\Controllers;
|
|
|
|
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
-use Catch\Base\CatchController;
|
|
|
|
-use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
|
-use Modules\Channel\Exceptions\ChannelBusinessException;
|
|
|
|
|
|
+use Catch\Base\CatchController;
|
|
|
|
+use Modules\Common\Errors\Errors;
|
|
use Modules\Channel\Models\PayProduct;
|
|
use Modules\Channel\Models\PayProduct;
|
|
use Modules\Channel\Models\PayTemplate;
|
|
use Modules\Channel\Models\PayTemplate;
|
|
use Modules\Channel\Models\PayTemplateItem;
|
|
use Modules\Channel\Models\PayTemplateItem;
|
|
|
|
+use Modules\Channel\Exceptions\ChannelBusinessException;
|
|
use Modules\Channel\Services\User\UserService;
|
|
use Modules\Channel\Services\User\UserService;
|
|
-use Modules\Common\Errors\Errors;
|
|
|
|
|
|
|
|
class PayTemplateController extends CatchController
|
|
class PayTemplateController extends CatchController
|
|
{
|
|
{
|
|
- use ValidatesRequests;
|
|
|
|
-
|
|
|
|
public function __construct(protected readonly PayTemplate $payTemplate,protected readonly PayTemplateItem $payTemplateItem,protected readonly PayProduct $payProduct)
|
|
public function __construct(protected readonly PayTemplate $payTemplate,protected readonly PayTemplateItem $payTemplateItem,protected readonly PayProduct $payProduct)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -40,63 +36,16 @@ class PayTemplateController extends CatchController
|
|
if(UserService::userHasRole($uid,'administrator')){
|
|
if(UserService::userHasRole($uid,'administrator')){
|
|
$uid = 0;
|
|
$uid = 0;
|
|
}
|
|
}
|
|
- if($uid) {
|
|
|
|
- $this->initPayTemplate($uid);
|
|
|
|
- }
|
|
|
|
$name = $request->get('name');
|
|
$name = $request->get('name');
|
|
- // 1-首充模板,2-非首充模板
|
|
|
|
- $type = $request->input('type');
|
|
|
|
$where = [[
|
|
$where = [[
|
|
- 'uid','=',$uid,
|
|
|
|
- // 'type', '=', $type,
|
|
|
|
|
|
+ 'uid','=',$uid
|
|
]];
|
|
]];
|
|
if($name){
|
|
if($name){
|
|
$where[] = ['name','like','%'.$name.'%'];
|
|
$where[] = ['name','like','%'.$name.'%'];
|
|
}
|
|
}
|
|
- $result = $this->payTemplate->orderBy('id','desc')->where($where)->paginate($request->input('limit', 20));
|
|
|
|
- foreach ($result as $item) {
|
|
|
|
- $item->status_str = $item->status ? '默认模板': '非默认模板';
|
|
|
|
- $item->type_str = 1 == $item->type ? '首充模板' : '非首充模板';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return $result;
|
|
|
|
|
|
+ return $this->payTemplate->orderBy('id','desc')->where($where)->paginate(20);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 如果优化是没有设置充值模板,那么就是用官方模板进行初始化
|
|
|
|
- * @param $uid
|
|
|
|
- */
|
|
|
|
- private function initPayTemplate($uid) {
|
|
|
|
- if(!$this->payTemplate->where('uid', $uid)->count()) {
|
|
|
|
- $systemPayTemplates = $this->payTemplate->where('uid', 0)->get();
|
|
|
|
- $now = date('Y-m-d H:i:s');
|
|
|
|
- foreach ($systemPayTemplates as $systemPayTemplate) {
|
|
|
|
- $payTemplate = $this->payTemplate->create([
|
|
|
|
- 'uid' => $uid,
|
|
|
|
- 'name' => $systemPayTemplate->name,
|
|
|
|
- 'status' => $systemPayTemplate->status,
|
|
|
|
- 'type' => $systemPayTemplate->type,
|
|
|
|
- ]);
|
|
|
|
- $payTemplateItems = $this->payTemplateItem->where([
|
|
|
|
- 'pay_template_id' => $systemPayTemplate->id, 'status' => 1,
|
|
|
|
- ])->get();
|
|
|
|
- $payTemplateItemDatas = [];
|
|
|
|
-
|
|
|
|
- foreach ($payTemplateItems as $item) {
|
|
|
|
- $payTemplateItemDatas[] = [
|
|
|
|
- 'pay_template_id' => $payTemplate->id,
|
|
|
|
- 'pay_product_id' => $item->pay_product_id,
|
|
|
|
- 'is_default' => $item->is_default,
|
|
|
|
- 'status' => $item->status,
|
|
|
|
- 'sequence' => $item->sequence,
|
|
|
|
- 'created_at' => $now,
|
|
|
|
- 'updated_at' => $now,
|
|
|
|
- ];
|
|
|
|
- }
|
|
|
|
- $this->payTemplateItem->insert($payTemplateItemDatas);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 添加模板
|
|
* 添加模板
|
|
@@ -106,24 +55,21 @@ class PayTemplateController extends CatchController
|
|
*/
|
|
*/
|
|
public function store(Request $request)
|
|
public function store(Request $request)
|
|
{
|
|
{
|
|
- $this->validate($request, [
|
|
|
|
- 'name' => 'required',
|
|
|
|
- 'options' => 'required',
|
|
|
|
- 'status' => 'required|in:0,1',
|
|
|
|
- 'type' => 'required|in:1,2'
|
|
|
|
- ]);
|
|
|
|
$uid = $this->getLoginUser()->id;
|
|
$uid = $this->getLoginUser()->id;
|
|
$name = $request->post('name');
|
|
$name = $request->post('name');
|
|
- // 0-非默认模板,1-默认模板
|
|
|
|
$status = $request->post('status');
|
|
$status = $request->post('status');
|
|
$options = $request->post('options');
|
|
$options = $request->post('options');
|
|
- // 1-首充模板,2-非首充模板
|
|
|
|
- $type = $request->input('type');
|
|
|
|
-
|
|
|
|
|
|
+ if(empty($name) || empty($options)){
|
|
|
|
+ ChannelBusinessException::throwError(Errors::PARAM_EMPTY);
|
|
|
|
+ }
|
|
if(UserService::userHasRole($uid,'administrator')){
|
|
if(UserService::userHasRole($uid,'administrator')){
|
|
$uid = 0;
|
|
$uid = 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ $exists = $this->payTemplate->where('uid',$uid)->where('name',$name)->count();
|
|
|
|
+ if($exists){
|
|
|
|
+ ChannelBusinessException::throwError(Errors::PAY_TEMPLATE_EXISTS_ERROR);
|
|
|
|
+ }
|
|
$option_list = json_decode($options,1);
|
|
$option_list = json_decode($options,1);
|
|
$data = [];
|
|
$data = [];
|
|
$default_optioin = 0;
|
|
$default_optioin = 0;
|
|
@@ -156,14 +102,11 @@ class PayTemplateController extends CatchController
|
|
|
|
|
|
$default_optioin = $default_optioin>0?$default_optioin:$option_list[0]['price'];
|
|
$default_optioin = $default_optioin>0?$default_optioin:$option_list[0]['price'];
|
|
|
|
|
|
- if($status == 1 && 0 == $uid){
|
|
|
|
- $this->payTemplate->where([
|
|
|
|
- 'uid' => $uid, 'type' => $type
|
|
|
|
- ])->update(['status'=>0]);
|
|
|
|
|
|
+ if($status == 1){
|
|
|
|
+ $this->payTemplate->where('uid',$uid)->update(['status'=>0]);
|
|
}
|
|
}
|
|
|
|
|
|
- $pay_template_info = $this->payTemplate->create(['name'=>$name,'uid'=>$uid,
|
|
|
|
- 'type' => $type, 'status' => $status]);
|
|
|
|
|
|
+ $pay_template_info = $this->payTemplate->create(['name'=>$name,'uid'=>$uid,'status'=>$status]);
|
|
|
|
|
|
foreach($option_list as $option){
|
|
foreach($option_list as $option){
|
|
$type = $option['type'];
|
|
$type = $option['type'];
|
|
@@ -190,7 +133,8 @@ class PayTemplateController extends CatchController
|
|
*/
|
|
*/
|
|
public function show($id)
|
|
public function show($id)
|
|
{
|
|
{
|
|
- $uid = $this->getLoginUser()->id;
|
|
|
|
|
|
+ //$uid = $this->getLoginUser()->id;
|
|
|
|
+ $uid= 1;
|
|
if(UserService::userHasRole($uid,'administrator')){
|
|
if(UserService::userHasRole($uid,'administrator')){
|
|
$uid = 0;
|
|
$uid = 0;
|
|
}
|
|
}
|
|
@@ -200,11 +144,11 @@ class PayTemplateController extends CatchController
|
|
}
|
|
}
|
|
|
|
|
|
$pay_template_item = $this->payTemplateItem->join('pay_products','pay_products.id','=','pay_template_items.pay_product_id')
|
|
$pay_template_item = $this->payTemplateItem->join('pay_products','pay_products.id','=','pay_template_items.pay_product_id')
|
|
- ->where('pay_template_id',$id)
|
|
|
|
- ->select('pay_products.price','pay_products.type','pay_products.given','pay_template_id','pay_product_id','is_first_pay','is_default','sequence','pay_template_items.id as pay_template_item_id')
|
|
|
|
- ->where('pay_template_items.status',1)
|
|
|
|
- ->orderBy('pay_template_items.sequence')
|
|
|
|
- ->get();
|
|
|
|
|
|
+ ->where('pay_template_id',$id)
|
|
|
|
+ ->select('pay_products.price','pay_products.type','pay_products.given','pay_template_id','pay_product_id','is_first_pay','is_default','sequence','pay_template_items.id as pay_template_item_id')
|
|
|
|
+ ->where('pay_template_items.status',1)
|
|
|
|
+ ->orderBy('pay_template_items.sequence')
|
|
|
|
+ ->get();
|
|
$type_list = collect($this->optionTypeList());
|
|
$type_list = collect($this->optionTypeList());
|
|
foreach($pay_template_item as $item){
|
|
foreach($pay_template_item as $item){
|
|
|
|
|
|
@@ -437,6 +381,7 @@ class PayTemplateController extends CatchController
|
|
public function optionTypeList(){
|
|
public function optionTypeList(){
|
|
return [
|
|
return [
|
|
['name'=>'普通充值','value'=>'COIN'],
|
|
['name'=>'普通充值','value'=>'COIN'],
|
|
|
|
+ ['name'=>'首充','value'=>'FIRST_COIN'],
|
|
['name'=>'包月','value'=>'MONTH'],
|
|
['name'=>'包月','value'=>'MONTH'],
|
|
['name'=>'包季','value'=>'QUARTER'],
|
|
['name'=>'包季','value'=>'QUARTER'],
|
|
['name'=>'包年','value'=>'YEAR']
|
|
['name'=>'包年','value'=>'YEAR']
|