cxgj/modules/admin/controllers/GoodsController.php
2023-11-28 15:18:01 +08:00

184 lines
5.8 KiB
PHP

<?php
/**
* @author wrx <it2bt.com>
* @description KISS
* @date 2021-4-19
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\admin\controllers;
use app\models\DeliveryRules;
use app\models\Goods;
use app\models\GoodsAttr;
use app\models\GoodsHub;
use app\models\PostageRules;
use app\models\TouristAgency;
use app\models\User;
use app\modules\admin\models\GoodsActionForm;
use app\modules\admin\models\GoodsEditForm;
use app\modules\admin\models\UserGuideForm;
use app\modules\file\models\FileModel;
use yii\base\BaseObject;
use yii\helpers\VarDumper;
use app\modules\admin\behaviors\LoginBehavior;
use app\modules\admin\models\PageForm;
class GoodsController extends Controller
{
public function behaviors()
{
return array_merge(parent::behaviors(), [
'login' => [
'class' => LoginBehavior::className(),
],
]);
}
public function actionEdit($id = 0)
{
$cx_mch_id = $this->cx_mch_id;
$goods_hub = GoodsHub::findOne([
'id' => $id,
'cx_mch_id' => $cx_mch_id,
'is_delete' => 0
]);
$goods = Goods::findOne([
'goods_hub_id' => $id,
'cx_mch_id' => $cx_mch_id,
'is_delete' => 0
]);
if(!empty($goods) && !empty($goods->prohibit_agency)){
$prohibit_agency = json_decode($goods->prohibit_agency,true);
$prohibit_agencys = TouristAgency::find()->alias('a')
->select('a.id as value,a.name')
->leftJoin(['u' => User::tableName()],'u.id=a.user_id')
->andWhere([
'u.is_delete' => 0,
'a.is_delete' => 0,
'a.status' => 1
])
->andWhere(['in','a.id',$prohibit_agency])
->asArray()
->all();
$goods->prohibit_agency = json_encode($prohibit_agencys,JSON_UNESCAPED_UNICODE);
}
$agency = TouristAgency::find()->alias('a')
->select('a.id as value,a.name')
->leftJoin(['u' => User::tableName()],'u.id=a.user_id')
->andWhere([
'u.is_delete' => 0,
'a.is_delete' => 0,
'a.status' => 1
])
->asArray()
->all();
if(empty($goods->use_attr)){
$attr = GoodsAttr::find()->where([
'goods_id' => $goods->id,
'is_delete' => 0,
])->orderBy(['sign_id' => SORT_ASC])->asArray()->all();
}
if($goods_hub == null){
$goods_hub = new GoodsHub();
$goods = new Goods();
$attr = new GoodsAttr();
}
if(\Yii::$app->request->post()){
$use_attr = \Yii::$app->request->post('use_attr');
$form = new GoodsEditForm();
$form->attributes = \Yii::$app->request->post();
$form->use_attr = $use_attr == null ? 'off' : $use_attr;
$form->cx_mch_id = $cx_mch_id;
$form->goods = $goods;
$form->goods_hub = $goods_hub;
$data = $form->save();
return $this->responseHandler($data);
}
return $this->render('edit',[
'postage_ruls' => PostageRules::findAll([
'is_delete' => 0,
'is_enable' => 1
]),
'delivery_ruls' => DeliveryRules::findAll([
'is_delete' => 0,
'is_enable' => 1
]),
'goods_hub' => $goods_hub,
'goods' => $goods,
'attr' => $attr,
'agency' => json_encode($agency,JSON_UNESCAPED_UNICODE),
]);
}
public function actionIndex()
{
return $this->render('index');
}
public function actionSearch()
{
$form = new GoodsActionForm();
$form->cx_mch_id = $this->cx_mch_id;
$form->page = \Yii::$app->request->get('page');
$form->limit = \Yii::$app->request->get('limit');
$form->status = \Yii::$app->request->get('status');
$form->plugin_sign = \Yii::$app->request->get('plugin_sign');
$form->name = \Yii::$app->request->get('name');
$data = $form->search();
return $this->responseHandler($data);
}
public function actionDel()
{
$form = new GoodsActionForm();
$form->cx_mch_id = $this->cx_mch_id;
$form->id = \Yii::$app->request->post('id');
$data = $form->del();
return $this->responseHandler($data);
}
public function actionBatchPublishYes()
{
$form = new GoodsActionForm();
$form->cx_mch_id = $this->cx_mch_id;
$form->batch_data_id = \Yii::$app->request->post('batch_data_id');
$data = $form->batchPublishYes();
return $this->responseHandler($data);
}
public function actionBatchPublishNo()
{
$form = new GoodsActionForm();
$form->cx_mch_id = $this->cx_mch_id;
$form->batch_data_id = \Yii::$app->request->post('batch_data_id');
$data = $form->batchPublishNo();
return $this->responseHandler($data);
}
public function actionBatchDel()
{
$form = new GoodsActionForm();
$form->cx_mch_id = $this->cx_mch_id;
$form->batch_data_id = \Yii::$app->request->post('batch_data_id');
$data = $form->batchDel();
return $this->responseHandler($data);
}
public function actionChart()
{
$form = new GoodsActionForm();
$cx_mch_id = $this->cx_mch_id;
$date = \Yii::$app->request->get('date');
$data = $form->chart($date,$cx_mch_id);
return $this->responseHandler($data);
}
}