123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- class refill_thirdControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $mod = Model('refill_third');
- $condition = [];
- if (trim($_GET['product_name']) != '') {
- $condition['product_name'] = ['like', '%' . $_GET['product_name'] . '%'];
- }
- $list = $mod->getThirdProductList($condition, 30);
- Tpl::output('product_list', $list);
- Tpl::output('page', $mod->showpage());
- Tpl::showpage('third.product.list');
- }
- public function product_addOp()
- {
- if (chksubmit()) {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => trim($_POST["product_name"]), "require" => "true", "message" => '产品名称不能为空'],
- ["input" => trim($_POST["refill_amount"]), "require" => "true", "message" => '产品面值不能为空'],
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- } else {
- $mod = Model('refill_third');
- $insert['product_name'] = trim($_POST['product_name']);
- $insert['refill_amount'] = trim($_POST['refill_amount']);
- $last_item = $mod->table('third_product')->order('system_code desc')->find();
- if (empty($last_item)) {
- $system_code = 'XYZ100001';
- } else {
- $last_code = $last_item['system_code'];
- $last_code = explode('XYZ',$last_code);
- $system_code = intval($last_code[1] + 1);
- $system_code = "XYZ{$system_code}";
- }
- $insert['system_code'] = $system_code;
- $result = $mod->addThirdProduct($insert);
- if ($result) {
- showMessage('添加成功', 'index.php?act=refill_third&op=index');
- } else {
- showMessage('添加失败');
- }
- }
- }
- Tpl::showpage('third.product.add');
- }
- public function product_editOp()
- {
- $system_code = $_GET['system_code'] ?? $_POST['system_code'];
- $mod = Model('refill_third');
- $third_product = $mod->findThirdProduct($system_code);
- if(empty($third_product)) {
- showMessage('产品不存在');
- }
- if(chksubmit()) {
- $update_data['product_name'] = trim($_POST['product_name']);
- $update_data['refill_amount'] = trim($_POST['refill_amount']);
- $result = $mod->editThirdProduct($system_code, $update_data);
- if ($result) {
- showMessage('编辑成功', 'index.php?act=refill_third&op=index');
- } else {
- showMessage('编辑失败');
- }
- }else{
- Tpl::output('third_product', $third_product);
- Tpl::showpage('third.product.edit');
- }
- }
- public function third_propriceOp()
- {
- $system_code = $_GET['system_code'] ?? $_POST['system_code'];
- $mod = Model('refill_third');
- $third_product = $mod->findThirdProduct($system_code);
- if(empty($third_product)) {
- showMessage('产品不存在');
- }
- $condition['system_code'] = $system_code;
- if(!empty($_GET['store_id']))
- {
- $condition['store_id'] = $_GET['store_id'];
- }
- $list = $mod->getProviderProductList($condition, 30);
- $providers = $this->providers(['type' => 3]);
- Tpl::output('providers', $providers);
- Tpl::output('product_list', $list);
- Tpl::output('third_product', $third_product);
- Tpl::output('recharge_type_text', ['直充','卡密','直充+卡密']);
- Tpl::output('page', $mod->showpage());
- Tpl::showpage('third.proprice.list');
- }
- public function third_proprice_addOp()
- {
- $system_code = $_GET['system_code'] ?? $_POST['system_code'];
- $mod = Model('refill_third');
- $third_product = $mod->findThirdProduct($system_code);
- if(empty($third_product)) {
- showMessage('产品不存在');
- }
- if (chksubmit()) {
- $obj_validate = new Validator();
- $obj_validate->validateparam = [
- ["input" => trim($_POST["store"]), "require" => "true", "message" => '通道信息不能为空'],
- ["input" => trim($_POST["channel_product_name"]), "require" => "true", "message" => '通道产品名称不能为空'],
- ["input" => trim($_POST["goods_id"]), "require" => "true", "message" => '商品ID不能为空'],
- ["input" => trim($_POST["channel_code"]), "require" => "true", "message" => '通道code不能为空'],
- ["input" => trim($_POST["channel_amount"]), "require" => "true", "message" => '折扣价格不能为空'],
- ["input" => trim($_POST["recharge_type"]), "require" => "true", "message" => '充值类型不能为空'],
- ];
- $error = $obj_validate->validate();
- if ($error != '') {
- showMessage($error);
- } else {
- $store = trim($_POST['store']);
- $store = explode('-',$store);
- $store_id = $store[0];
- $channel_name = $store[1];
- $goods_id = trim($_POST['goods_id']);
- $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
- if(!empty($channel_product)) {
- showMessage('此通道已关联过此产品');
- exit;
- }
- $mod = Model('refill_third');
- $insert['channel_name'] = $channel_name;
- $insert['store_id'] = $store_id;
- $insert['channel_product_name'] = trim($_POST['channel_product_name']);
- $insert['goods_id'] = $goods_id;
- $insert['channel_code'] = trim($_POST['channel_code']);
- $insert['channel_amount'] = trim($_POST['channel_amount']);
- $insert['recharge_type'] = trim($_POST['recharge_type']);
- $insert['system_code'] = $system_code;
- $result = $mod->addProviderProduct($insert);
- if ($result) {
- showMessage('添加成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
- } else {
- showMessage('添加失败');
- }
- }
- } else {
- $providers = $this->providers(['type' => 3]);
- Tpl::output('providers', $providers);
- Tpl::output('third_product', $third_product);
- Tpl::showpage('third.proprice.add');
- }
- }
- public function third_proprice_editOp()
- {
- $system_code = $_GET['system_code'] ?? $_POST['system_code'];
- $mod = Model('refill_third');
- $third_product = $mod->findThirdProduct($system_code);
- if(empty($third_product)) {
- showMessage('产品不存在');
- }
- $store_id = $_GET['store_id'] ?? $_POST['store_id'];
- $goods_id = $_GET['goods_id'] ?? $_POST['goods_id'];
- $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
- if(empty($channel_product)) {
- showMessage('此通道关联产品不存在');
- }
- if (chksubmit()) {
- $update_data = [];
- $update_data['channel_product_name'] = trim($_POST['channel_product_name']);
- $update_data['channel_code'] = trim($_POST['channel_code']);
- $update_data['channel_amount'] = trim($_POST['channel_amount']);
- $update_data['recharge_type'] = trim($_POST['recharge_type']);
- $result = $mod->edit_provider_product($system_code,$store_id,$goods_id,$update_data);
- if ($result) {
- showMessage('编辑成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
- } else {
- showMessage('编辑失败');
- }
- } else {
- Tpl::output('third_product', $third_product);
- Tpl::output('channel_product', $channel_product);
- Tpl::showpage('third.proprice.edit');
- }
- }
- }
|