119 lines
4.1 KiB
PHP
119 lines
4.1 KiB
PHP
<?php
|
|
namespace app\controllers\merchant;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\components\TesttaskJob;
|
|
use app\components\SendLinkJob;
|
|
use app\models\common\Store;
|
|
//商品加料
|
|
class UnitController extends CommonController{
|
|
public $enableCsrfValidation = false;
|
|
function actionMain() {
|
|
Yii::$app->queue->push(new SendLinkJob([
|
|
'link' => 'https://baidu.com',
|
|
'startAt' => time(),
|
|
'times' => 1,
|
|
]));
|
|
}
|
|
public function actionJobPush(){
|
|
|
|
Yii::$app->queue->push(new TesttaskJob([
|
|
'url' => 'http://example.com/image.jpg',
|
|
'file' => '/tmp/image.jpg',
|
|
]));
|
|
|
|
}
|
|
public function actionJobDelay(){
|
|
Yii::$app->queue->delay(2*60)->push(new TesttaskJob([
|
|
'url' => '111',
|
|
'file' => '222'
|
|
]));
|
|
}
|
|
|
|
|
|
|
|
public function actionGetUnitList(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isGet){
|
|
$table= (new \yii\db\Query())
|
|
->from('{{%ybwm_core_unit}}');
|
|
$result=axios_request();
|
|
if($result['id']){
|
|
$re=$table->where(['id'=>$result['id']])->one();
|
|
}else{
|
|
$re=$table->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$this->wqData['storeId']])->all();
|
|
}
|
|
return $this->result(1,'成功',$re);
|
|
|
|
}
|
|
}
|
|
public function actionUnitSave(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$shop_id=$this->wqData['storeId'];
|
|
if(!$shop_id){
|
|
return $this->result(3,'无效的门店,请先添加商店');die;
|
|
}
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->wqData['storeId'];
|
|
$data=array(
|
|
'sort'=>$result['sort'],
|
|
'name'=>$result['name'],
|
|
'uniacid'=>$this->wqData['uniacid'],
|
|
'storeId'=>$storeId,
|
|
);
|
|
if($result['id']){
|
|
$re=YII::$app->db->createCommand()->update('{{%ybwm_core_unit}}',$data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['createdAt']=time();
|
|
$row= (new \yii\db\Query())
|
|
->from('{{%ybwm_core_unit}}')
|
|
->where(['uniacid'=>$this->wqData['uniacid'],'deleteAt'=>0,'storeId'=>$storeId,'name'=>trim($result['name'])])
|
|
->one();
|
|
if($row){
|
|
return $this->result(2,'该单位已存在');
|
|
}
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_core_unit}}', $data)->execute();
|
|
}
|
|
if ($re!=false) {
|
|
return $this->result(1,'成功');
|
|
} else {
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function actionChangeDisplay(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_unit}}', ['display'=>$result['display']],'id=:id', ['id' =>$result['id']])->execute();
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function actionUnitDel(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
if(is_array($result['id'])){
|
|
$re=YII::$app->db->createCommand()->update('{{%ybwm_core_unit}}',['deleteAt'=>time()], ['in','id',$result['id']])->execute();
|
|
}else {
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_unit}}', ['deleteAt' => time()], 'id=:id', ['id' => $result['id']])->execute();
|
|
|
|
}if($re!==false){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|