Commit 4294f896 authored by ZhuChunYang's avatar ZhuChunYang

update

parent 3d3683e5
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Time: 10:26 * Time: 10:26
*/ */
namespace backend\controllers; namespace backend\controllers;
use backend\models\coin\CoinApplicationForm;
use common\models\psources\CoinAppCate; use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplication; use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory; use common\models\psources\CoinApplicationCategory;
...@@ -30,7 +31,7 @@ class ApplicationController extends BaseController ...@@ -30,7 +31,7 @@ class ApplicationController extends BaseController
if($app_ids){ if($app_ids){
$app_items = array_column($app_ids,'app_id'); $app_items = array_column($app_ids,'app_id');
} }
$where[] = ['in','id',[$app_items]]; $where[] = ['in','id',$app_items];
$data = CoinApplication::getList($page, $limit, $where); $data = CoinApplication::getList($page, $limit, $where);
return $data; return $data;
}else{ }else{
...@@ -52,12 +53,21 @@ class ApplicationController extends BaseController ...@@ -52,12 +53,21 @@ class ApplicationController extends BaseController
public function actionAdd() public function actionAdd()
{ {
if(Yii::$app->request->isPost){ if(Yii::$app->request->isPost){
Yii::$app->response->format = 'json';
$category_id = Yii::$app->request->get('category_id'); $category_id = Yii::$app->request->get('category_id');
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
$fields = ['name','sort','icon','type','native_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type']; $fields = ['category_id','name','sort','icon','type','native_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'];
$params = array_merge(Yii::$app->request->post(),['category_id' => $category_id]); $params = array_merge(Yii::$app->request->post(),['category_id' => $category_id]);
$params = $this->initParams($params, $fields); $params = $this->initParams($params, $fields);
var_dump($params);die; $coin_applicateion_form = new CoinApplicationForm();
$coin_applicateion_form->setScenario(CoinApplicationForm::SCENARIO_ADD);
$coin_applicateion_form->load($params,'');
$result = $coin_applicateion_form->add();
if($result['code'] == 0){
$this->success('添加成功', '/admin/application/list?id='.$category_id);
}else{
$this->error($result['msg'], Yii::$app->request->getReferrer());
}
} }
return $this->render('add'); return $this->render('add');
} }
......
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/16
* Time: 11:43
*/
namespace backend\models\coin;
use backend\models\BaseForm;
use common\models\psources\CoinApplicationCategory;
class CoinApplicationCategoryForm extends BaseForm
{
const SCENARIO_ADD = 'add';
const SCENARIO_EDIT = 'edit';
public $id;
public $name;
public $sort;
public $icon;
public $pid;
public $banner;
public $banner_url;
public function scenarios()
{
return [
self::SCENARIO_ADD => ['name', 'sort', 'icon', 'banner', 'banner_url'],
self::SCENARIO_EDIT => ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'],
];
}
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => '名称',
'icon' => '图标',
'sort' => '排序',
'banner' => 'banner图片',
'banner_url' => 'banner链接'
];
}
public function rules()
{
return [
[['name'], 'required', 'on' => self::SCENARIO_ADD],
[['id', 'name', 'sort'], 'required', 'on' => self::SCENARIO_EDIT],
['sort', 'default', 'value' => 1],
['sort', 'integer'],
['icon', 'default', 'value' => 0],
['banner', 'default', 'value' => 0],
['name', 'checkName'],
];
}
public function checkName($attribute, $params)
{
$res = CoinApplicationCategory::find()->where(['name' => $this->$attribute])->one();
$scenario = $this->getScenario();
if ($scenario == self::SCENARIO_ADD) {
if ($res) {
$this->addError($attribute, '应用分类名称已存在');
}
} else if ($scenario == self::SCENARIO_EDIT) {
if ($res && $res->id != $this->id) {
$this->addError($attribute, '应用分类名称已存在');
}
}
}
/**
* 添加应用
*/
public function add()
{
if ($this->validate()) {
$coin_applicate_category = new CoinApplicationCategory();
$coin_applicate_category->setAttributes($this->attributes, false);
$coin_applicate_category->save();
return ['code' => 0, 'msg' => '应用分类添加成功!'];
} else {
$error = self::getModelError($this);
return ['code' => 1, 'msg' => $error];
}
}
}
\ No newline at end of file
...@@ -2,38 +2,33 @@ ...@@ -2,38 +2,33 @@
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: ZCY * User: ZCY
* Date: 2018/10/12 * Date: 2018/10/16
* Time: 19:10 * Time: 11:43
*/ */
namespace backend\models\coin; namespace backend\models\coin;
use backend\models\BaseForm; use backend\models\BaseForm;
use common\models\psources\CoinApplicationCategory;
class CoinApplicationForm extends BaseForm class CoinApplicationCategoryForm extends BaseForm
{ {
const SCENARIO_ADD = 'add'; const SCENARIO_ADD = 'add';
const SCENARIO_EDIT = 'edit'; const SCENARIO_EDIT = 'edit';
public $id; public $id;
public $name; public $name;
public $icon;
public $sort; public $sort;
public $type; public $icon;
public $native_url; public $pid;
public $h5_url; public $banner;
public $android_url; public $banner_url;
public $ios_url;
public $app_store_url;
public $advertise;
public $description;
public $image_ids;
public $redirect_type;
public function scenarios() public function scenarios()
{ {
return [ return [
self::SCENARIO_ADD => ['name','sort','icon','banner','banner_url'], self::SCENARIO_ADD => ['name', 'sort', 'icon', 'banner', 'banner_url'],
self::SCENARIO_EDIT => ['id','name','sort','icon','banner','banner_url'], self::SCENARIO_EDIT => ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'],
]; ];
} }
...@@ -45,15 +40,8 @@ class CoinApplicationForm extends BaseForm ...@@ -45,15 +40,8 @@ class CoinApplicationForm extends BaseForm
'name' => '名称', 'name' => '名称',
'icon' => '图标', 'icon' => '图标',
'sort' => '排序', 'sort' => '排序',
'type' => '类型', 'banner' => 'banner图片',
'native_url' => '原生链接', 'banner_url' => 'banner链接'
'h5_url' => 'h5链接',
'android_url' => '安卓链接',
'ios_url' => 'ios企业版链接',
'app_store_url' => 'ios商店版链接',
'advertise' => '宣传语',
'description' => '介绍',
'redirect_type' => '跳转方式',
]; ];
} }
...@@ -61,11 +49,11 @@ class CoinApplicationForm extends BaseForm ...@@ -61,11 +49,11 @@ class CoinApplicationForm extends BaseForm
{ {
return [ return [
[['name'], 'required', 'on' => self::SCENARIO_ADD], [['name'], 'required', 'on' => self::SCENARIO_ADD],
[['id','name','sort'], 'required', 'on' => self::SCENARIO_EDIT], [['id', 'name', 'sort'], 'required', 'on' => self::SCENARIO_EDIT],
['sort', 'default', 'value' => 1], ['sort', 'default', 'value' => 1],
['sort', 'integer'], ['sort', 'integer'],
['icon', 'default', 'value' => 0], ['icon', 'default', 'value' => 0],
['banner','default','value' => 0], ['banner', 'default', 'value' => 0],
['name', 'checkName'], ['name', 'checkName'],
]; ];
} }
...@@ -74,32 +62,31 @@ class CoinApplicationForm extends BaseForm ...@@ -74,32 +62,31 @@ class CoinApplicationForm extends BaseForm
{ {
$res = CoinApplicationCategory::find()->where(['name' => $this->$attribute])->one(); $res = CoinApplicationCategory::find()->where(['name' => $this->$attribute])->one();
$scenario = $this->getScenario(); $scenario = $this->getScenario();
if($scenario == self::SCENARIO_ADD){ if ($scenario == self::SCENARIO_ADD) {
if($res){ if ($res) {
$this->addError($attribute,'应用分类名称已存在'); $this->addError($attribute, '应用分类名称已存在');
} }
}else if($scenario == self::SCENARIO_EDIT){ } else if ($scenario == self::SCENARIO_EDIT) {
if($res && $res->id != $this->id){ if ($res && $res->id != $this->id) {
$this->addError($attribute,'应用分类名称已存在'); $this->addError($attribute, '应用分类名称已存在');
} }
} }
} }
/** /**
* 添加应用分类 * 添加应用分类
*/ */
public function add() public function add()
{ {
if($this->validate()){ if ($this->validate()) {
$coin_applicate_category = new CoinApplicationCategory(); $coin_applicate_category = new CoinApplicationCategory();
$coin_applicate_category->setAttributes($this->attributes,false); $coin_applicate_category->setAttributes($this->attributes, false);
$coin_applicate_category->save(); $coin_applicate_category->save();
return ['code' => 0,'msg' => '应用分类添加成功!']; return ['code' => 0, 'msg' => '应用分类添加成功!'];
}else{ } else {
$error = self::getModelError($this); $error = self::getModelError($this);
return ['code' => 1,'msg' => $error]; return ['code' => 1, 'msg' => $error];
} }
} }
......
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/12
* Time: 19:10
*/
namespace backend\models\coin;
use backend\models\BaseForm;
use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplication;
use Yii;
class CoinApplicationForm extends BaseForm
{
const SCENARIO_ADD = 'add';
const SCENARIO_EDIT = 'edit';
public $id;
public $category_id;
public $name;
public $icon;
public $sort;
public $type;
public $native_url;
public $h5_url;
public $android_url;
public $ios_url;
public $app_store_url;
public $advertise;
public $description;
public $image_ids;
public $redirect_type;
public function scenarios()
{
return [
self::SCENARIO_ADD => ['category_id','name','sort','icon','type','native_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'],
self::SCENARIO_EDIT => ['id','name','sort','icon','type','native_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'],
];
}
public function attributeLabels()
{
return [
'id' => 'ID',
'category_id' => '分类ID',
'name' => '名称',
'icon' => '图标',
'sort' => '排序',
'type' => '类型',
'native_url' => '原生链接',
'h5_url' => 'h5链接',
'android_url' => '安卓链接',
'ios_url' => 'ios企业版链接',
'app_store_url' => 'ios商店版链接',
'advertise' => '宣传语',
'description' => '介绍',
'redirect_type' => '跳转方式',
];
}
public function rules()
{
return [
[['name','category_id'], 'required', 'on' => self::SCENARIO_ADD],
['sort', 'default', 'value' => 1],
['sort', 'integer'],
['icon', 'default', 'value' => 0],
['advertise','string', 'length' => [0, 20]],
['description','string', 'length' => [0, 500]],
['type', 'default', 'value' => 1],
['redirect_type', 'default', 'value' => 1],
];
}
public function checkName($attribute, $params)
{
$res = CoinApplication::find()->where(['name' => $this->$attribute])->one();
$scenario = $this->getScenario();
if($scenario == self::SCENARIO_ADD){
if($res){
$this->addError($attribute,'应用名称已存在');
}
}else if($scenario == self::SCENARIO_EDIT){
if($res && $res->id != $this->id){
$this->addError($attribute,'应用名称已存在');
}
}
}
/**
* 添加应用
*/
public function add()
{
if($this->validate()){
$tr = CoinApplication::getDb()->beginTransaction();
try{
$coin_applicate = new CoinApplication();
$coin_applicate->setAttributes($this->attributes,false);
$res = $coin_applicate->save();
if($res){
$coin_app_cate = new CoinAppCate();
$coin_app_cate->app_id = $coin_applicate->id;
$coin_app_cate->cate_id = $this->category_id;
$coin_app_cate->save();
$tr->commit();
}
return ['code' => 0,'msg' => '应用添加成功!'];
}catch (\Exception $e){
$tr->rollBack();
return ['code' => 1,'msg' => $e->getMessage()];
}
}else{
$error = self::getModelError($this);
return ['code' => 1,'msg' => $error];
}
}
}
\ No newline at end of file
...@@ -77,12 +77,6 @@ ...@@ -77,12 +77,6 @@
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">众筹价格</label>
<div class="layui-input-block">
<input class="layui-input" name="" placeholder="¥" value="">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">宣传语</label> <label class="layui-form-label">宣传语</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" class="layui-input" name="advertise" value=""> <input type="text" class="layui-input" name="advertise" value="">
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
</a> </a>
</div> </div>
</div> </div>
<input id="category_id" type="hidden" value="<?= $parent_category->id ?>">
<div class="layui-col-md8"> <div class="layui-col-md8">
<table class="layui-table" id="table1" lay-filter="table1"></table> <table class="layui-table" id="table1" lay-filter="table1"></table>
</div> </div>
...@@ -29,7 +30,7 @@ ...@@ -29,7 +30,7 @@
<script type="text/javascript"> <script type="text/javascript">
var table = layui.table; var table = layui.table;
var category_id = $("#parent_id").val(); var category_id = $("#category_id").val();
table.render({ table.render({
elem: '#table1', elem: '#table1',
page: true, page: true,
......
...@@ -23,20 +23,6 @@ class CoinAppCate extends BaseActiveRecord ...@@ -23,20 +23,6 @@ class CoinAppCate extends BaseActiveRecord
return '{{%coin_app_cate}}'; return '{{%coin_app_cate}}';
} }
public function beforeSave($instert)
{
if (parent::beforeSave($instert)) {
if ($this->isNewRecord) {
$this->create_time = Yii::$app->formatter->asTimestamp('now');
} else {
$this->update_time = Yii::$app->formatter->asTimestamp('now');
}
return true;
} else {
return false;
}
}
public static function getAppIdByCateId($cate_id) public static function getAppIdByCateId($cate_id)
{ {
return self::find()->where(['cate_id' => $cate_id])->asArray()->all(); return self::find()->where(['cate_id' => $cate_id])->asArray()->all();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment