Commit 4294f896 authored by ZhuChunYang's avatar ZhuChunYang

update

parent 3d3683e5
......@@ -6,6 +6,7 @@
* Time: 10:26
*/
namespace backend\controllers;
use backend\models\coin\CoinApplicationForm;
use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory;
......@@ -30,7 +31,7 @@ class ApplicationController extends BaseController
if($app_ids){
$app_items = array_column($app_ids,'app_id');
}
$where[] = ['in','id',[$app_items]];
$where[] = ['in','id',$app_items];
$data = CoinApplication::getList($page, $limit, $where);
return $data;
}else{
......@@ -52,12 +53,21 @@ class ApplicationController extends BaseController
public function actionAdd()
{
if(Yii::$app->request->isPost){
Yii::$app->response->format = 'json';
$category_id = Yii::$app->request->get('category_id');
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 = $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');
}
......
<?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
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/12
* Time: 19:10
*/
namespace backend\models\coin;
use backend\models\BaseForm;
class CoinApplicationForm extends BaseForm
{
const SCENARIO_ADD = 'add';
const SCENARIO_EDIT = 'edit';
public $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 => ['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' => '排序',
'type' => '类型',
'native_url' => '原生链接',
'h5_url' => 'h5链接',
'android_url' => '安卓链接',
'ios_url' => 'ios企业版链接',
'app_store_url' => 'ios商店版链接',
'advertise' => '宣传语',
'description' => '介绍',
'redirect_type' => '跳转方式',
];
}
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];
}
}
/**
* 编辑应用分类
*/
public function edit()
{
if($this->validate()){
$coin_applicate_category = CoinApplicationCategory::getCategoryById($this->id);
if($coin_applicate_category){
$coin_applicate_category->setAttributes($this->attributes,false);
$coin_applicate_category->save();
return ['code' => 0,'msg' => '应用分类修改成功!'];
}else{
return ['code' => 1,'msg' => '应用分类不存在'];
}
}else{
$error = self::getModelError($this);
return ['code' => 1,'msg' => $error];
}
}
/**
* @param $id
* 删除应用分类
*/
public function del($id)
{
$coin_applicate_category = CoinApplicationCategory::getCategoryById($id);
if($coin_applicate_category){
$coin_applicate_category->delete();
return ['code' => 0,'msg' => '应用分类删除成功'];
}else{
return ['code' => 1,'msg' => '应用分类不存在'];
}
}
<?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];
}
}
/**
* 编辑应用分类
*/
public function edit()
{
if($this->validate()){
$coin_applicate_category = CoinApplicationCategory::getCategoryById($this->id);
if($coin_applicate_category){
$coin_applicate_category->setAttributes($this->attributes,false);
$coin_applicate_category->save();
return ['code' => 0,'msg' => '应用分类修改成功!'];
}else{
return ['code' => 1,'msg' => '应用分类不存在'];
}
}else{
$error = self::getModelError($this);
return ['code' => 1,'msg' => $error];
}
}
/**
* @param $id
* 删除应用分类
*/
public function del($id)
{
$coin_applicate_category = CoinApplicationCategory::getCategoryById($id);
if($coin_applicate_category){
$coin_applicate_category->delete();
return ['code' => 0,'msg' => '应用分类删除成功'];
}else{
return ['code' => 1,'msg' => '应用分类不存在'];
}
}
}
\ No newline at end of file
<?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 @@
</div>
</div>
<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>
<div class="layui-input-block">
<input type="text" class="layui-input" name="advertise" value="">
......
......@@ -14,6 +14,7 @@
</a>
</div>
</div>
<input id="category_id" type="hidden" value="<?= $parent_category->id ?>">
<div class="layui-col-md8">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
......@@ -29,7 +30,7 @@
<script type="text/javascript">
var table = layui.table;
var category_id = $("#parent_id").val();
var category_id = $("#category_id").val();
table.render({
elem: '#table1',
page: true,
......
......@@ -23,20 +23,6 @@ class CoinAppCate extends BaseActiveRecord
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)
{
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