363 lines
13 KiB
PHP
363 lines
13 KiB
PHP
<?php
|
|
namespace app\controllers\channel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use app\models\common\Printing;
|
|
use app\models\common\Store;
|
|
use app\models\common\Export;
|
|
class IntegralShopController extends CommonController{
|
|
//积分分类列表
|
|
public function actionGoodsType(){
|
|
$result=axios_request();
|
|
$page=$result['page']?:1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->select('id,name,icon,from_unixtime(createdAt) createdAt,display,sort')
|
|
->from('{{%ybwm_core_category}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'item'=>8]);
|
|
$list=$table
|
|
->offset($num)
|
|
->limit($limit)
|
|
->orderBy('id desc')
|
|
->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
//保存积分分类
|
|
public function actionSaveGoodsType(){
|
|
$result=axios_request();
|
|
$request = Yii::$app->request;
|
|
if($request->isGet){
|
|
$info=(new \yii\db\Query())
|
|
->from('{{%ybwm_core_category}}')
|
|
->where('id=:id',[':id'=>$result['id']])->one();
|
|
return $this->result(1, '成功',$info);
|
|
}
|
|
if(!$result['name']){
|
|
return $this->result(2,'分类名称不能为空!');
|
|
}
|
|
$data['name']=$result['name'];
|
|
$data['icon']=$result['icon'];
|
|
$data['display']=$result['display'];
|
|
$data['sort']=$result['sort'];
|
|
$data['item']=8;
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$re = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['uniacid']=$this->wqData['uniacid'];
|
|
$data['createdAt']=time();
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_core_category}}', $data)->execute();
|
|
}
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
//修改分类
|
|
public function actionModifyGoodsType(){
|
|
$post=axios_request();
|
|
if($post['type']==1){
|
|
//显示隐藏
|
|
$data['display']=$post['display'];
|
|
}
|
|
if($post['type']==2){
|
|
//删除
|
|
$data['deleteAt']=time();
|
|
}
|
|
$data['changeAt']=time();
|
|
if(is_array($post['id'])){
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', $data, ['in','id',$post['id']])->execute();
|
|
}else{
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_core_category}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
|
}
|
|
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
//商品列表
|
|
public function actionGoodsList(){
|
|
$result=axios_request();
|
|
$page=$result['page']?:1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->select('a.id,a.name,a.icon,a.display,a.sort,b.name as typeName,a.score,a.money,a.stock,a.convertNum,a.type')
|
|
->from('{{%ybwm_integral_goods}} as a')
|
|
->join('LEFT JOIN', '{{%ybwm_core_category}} as b', 'b.id = a.typeId')
|
|
->where(['a.deleteAt'=>0,'a.uniacid'=>$this->wqData['uniacid']]);
|
|
if($result['name']){
|
|
$table->andWhere(['like','a.name',$result['name']]);
|
|
}
|
|
$list=$table
|
|
->offset($num)
|
|
->limit($limit)
|
|
->orderBy('id desc')
|
|
->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
//保存商品
|
|
public function actionSaveGoods(){
|
|
$result=axios_request();
|
|
$request = Yii::$app->request;
|
|
if($request->isGet){
|
|
$info=(new \yii\db\Query())
|
|
->from('{{%ybwm_integral_goods}}')
|
|
->where('id=:id',[':id'=>$result['id']])->one();
|
|
$info['deliveryMode']=json_decode($info['deliveryMode'],true)?:[];
|
|
$typeList=(new \yii\db\Query())
|
|
->from('{{%ybwm_core_category}}')
|
|
->where('uniacid=:uniacid AND item=8 AND deleteAt=0',[':uniacid'=>$this->wqData['uniacid']])->all();
|
|
$info['typeList']=$typeList;
|
|
return $this->result(1, '成功',$info);
|
|
}
|
|
if(!$result['name']){
|
|
return $this->result(2,'商品名称不能为空!');
|
|
}
|
|
if(!$result['deliveryMode']){
|
|
return $this->result(2,'配送支持不能为空!');
|
|
}
|
|
$data['name']=$result['name'];
|
|
$data['icon']=$result['icon'];
|
|
$data['display']=$result['display'];
|
|
$data['sort']=$result['sort'];
|
|
$data['type']=$result['type'];
|
|
$data['stock']=$result['stock'];
|
|
$data['score']=$result['score'];
|
|
$data['money']=$result['money'];
|
|
$data['isLimit']=$result['isLimit'];
|
|
$data['num']=$result['num'];
|
|
$data['notice']=$result['notice'];
|
|
$data['balance']=$result['balance'];
|
|
$data['typeId']=$result['typeId'];
|
|
$data['price']=$result['price'];
|
|
$data['deliveryMoney']=$result['deliveryMoney'];
|
|
$data['isHot']=$result['isHot'];
|
|
$data['deliveryMode']=json_encode($result['deliveryMode']);
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$re = Yii::$app->db->createCommand()->update('{{%ybwm_integral_goods}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['uniacid']=$this->wqData['uniacid'];
|
|
$data['createdAt']=time();
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_integral_goods}}', $data)->execute();
|
|
}
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
//修改商品
|
|
public function actionModifyGoods(){
|
|
$post=axios_request();
|
|
if($post['type']==1){
|
|
//显示隐藏
|
|
$data['display']=$post['display'];
|
|
}
|
|
if($post['type']==2){
|
|
//删除
|
|
$data['deleteAt']=time();
|
|
}
|
|
$data['changeAt']=time();
|
|
if(is_array($post['id'])){
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_integral_goods}}', $data, ['in','id',$post['id']])->execute();
|
|
}else{
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_integral_goods}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
|
}
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
//自提列表
|
|
public function actionSelfList(){
|
|
$result=axios_request();
|
|
$page=$result['page']?:1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->select('id,name,address,display,tel,linkMan')
|
|
->from('{{%ybwm_mention_point}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid']]);
|
|
$list=$table
|
|
->offset($num)
|
|
->limit($limit)
|
|
->orderBy('id desc')
|
|
->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
//保存自提
|
|
public function actionSaveSelf(){
|
|
$result=axios_request();
|
|
$request = Yii::$app->request;
|
|
if($request->isGet){
|
|
$info=(new \yii\db\Query())
|
|
->from('{{%ybwm_mention_point}}')
|
|
->where('id=:id',[':id'=>$result['id']])->one();
|
|
return $this->result(1, '成功',$info);
|
|
}
|
|
if(!$result['name']){
|
|
return $this->result(2,'名称不能为空!');
|
|
}
|
|
if(!$result['linkMan']){
|
|
return $this->result(2,'联系人不能为空!');
|
|
}
|
|
if(!$result['tel']){
|
|
return $this->result(2,'联系电话不能为空!');
|
|
}
|
|
if(!$result['address']){
|
|
return $this->result(2,'地址不能为空!');
|
|
}
|
|
if(!$result['lat'] || !$result['lng']){
|
|
return $this->result(2,'坐标不能为空!');
|
|
}
|
|
$data['name']=$result['name'];
|
|
$data['address']=$result['address'];
|
|
$data['display']=$result['display'];
|
|
$data['address']=$result['address'];
|
|
$data['lat']=$result['lat'];
|
|
$data['lng']=$result['lng'];
|
|
$data['tel']=$result['tel'];
|
|
$data['linkMan']=$result['linkMan'];
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$re = Yii::$app->db->createCommand()->update('{{%ybwm_mention_point}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['uniacid']=$this->wqData['uniacid'];
|
|
$data['createdAt']=time();
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_mention_point}}', $data)->execute();
|
|
}
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
//修改自提
|
|
public function actionModifySelf(){
|
|
$post=axios_request();
|
|
if($post['type']==1){
|
|
//显示隐藏
|
|
$data['display']=$post['display'];
|
|
}
|
|
if($post['type']==2){
|
|
//删除
|
|
$data['deleteAt']=time();
|
|
}
|
|
$data['changeAt']=time();
|
|
if(is_array($post['id'])){
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_mention_point}}', $data, ['in','id',$post['id']])->execute();
|
|
}else{
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_mention_point}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
|
}
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
|
|
//订单列表
|
|
public function actionOrderList(){
|
|
$result=axios_request();
|
|
$page=$result['page']?:1;
|
|
$num=($page-1)*10;
|
|
$limit=10;
|
|
$table=(new \yii\db\Query())
|
|
->select('a.id,a.userId,b.userName,a.outTradeNo,a.goodsName,a.goodsType,a.convertNum,a.score,a.money,a.state,a.receiveName,a.receiveTel,a.receiveAddress,from_unixtime(a.createdAt) createdAt,a.deliveryMode,a.selfCode')
|
|
->from('{{%ybwm_integral_order}} as a')
|
|
->join('LEFT JOIN', '{{%ybwm_member}} as b', 'b.id = a.userId')
|
|
->where(['a.deleteAt'=>0,'a.uniacid'=>$this->wqData['uniacid']])
|
|
->andWhere(['<>','state','1']);
|
|
if($result['type']){
|
|
$table->andWhere('a.goodsType='.$result['type']);
|
|
}
|
|
if($result['state']){
|
|
$table->andWhere('a.state='.$result['state']);
|
|
}
|
|
$keyWords=$result['keyword'];
|
|
if($keyWords){
|
|
$table->andWhere(['or',['like','a.receiveTel',$keyWords],['like','a.goodsName',$keyWords]]);
|
|
}
|
|
if($keyWords){
|
|
$table->andWhere(['or',['like','a.receiveTel',$keyWords],['like','a.goodsName',$keyWords]]);
|
|
}
|
|
if($result['export']==1){
|
|
Export::ExchangeExport($table->all());
|
|
}
|
|
$list=$table
|
|
->offset($num)
|
|
->limit($limit)
|
|
->orderBy('a.id desc')
|
|
->all();
|
|
$count=$table->count();
|
|
return $this->result(1, '成功',$list,$count);
|
|
}
|
|
|
|
//积分分类列表
|
|
public function actionGoodsTypeAll(){
|
|
$table=(new \yii\db\Query())
|
|
->select('id,name')
|
|
->from('{{%ybwm_core_category}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'item'=>8])
|
|
->orderBy('id desc')
|
|
->all();
|
|
return $this->result(1, '成功',$table);
|
|
}
|
|
|
|
//发货
|
|
public function actionModifyOrder(){
|
|
$result=axios_request();
|
|
$res='';
|
|
if($result['type']==1){
|
|
//发货
|
|
$data['logisticsName']=$result['logisticsName'];
|
|
$data['logisticsCode']=$result['logisticsCode'];
|
|
$data['state']=3;
|
|
$data['deliverAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_integral_order}}', $data,'id=:id', ['id' =>$result['id']])->execute();
|
|
}
|
|
if($result['type']==2){
|
|
//核销
|
|
$data['state']=4;
|
|
$data['completeAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_integral_order}}', $data,'id=:id', ['id' =>$result['id']])->execute();
|
|
}
|
|
if($result['type']==3){
|
|
$data['deleteAt']=time();
|
|
$res = Yii::$app->db->createCommand()->update('{{%ybwm_integral_order}}', $data,'id=:id', ['id' =>$result['id']])->execute();
|
|
}
|
|
if($res){
|
|
return $this->result(1, '成功');
|
|
}else{
|
|
return $this->result(2, '失败');
|
|
}
|
|
}
|
|
|
|
public function actionIntegralPrint(){
|
|
$result=axios_request();
|
|
$storeId=Store::getMainStore($this->wqData['uniacid'])['id'];
|
|
//echo $storeId;die;
|
|
$result=Printing::integralOrderPrint($result['id'],$storeId);
|
|
if($result){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
|
|
}
|