Commit 547c553d by 杨树贤

添加按钮文字返回

parent f7e4e263
<?php
namespace App\Http\Controllers;
use App\Model\GoodsModel;
use App\Model\UploadGoodsModel;
use Illuminate\Http\Request;
class ApiController extends Controller
{
public function GoodsInfo(Request $request){
$Field = ['goods_name/like','status/eq','start_time','end_time','goods_id/eq','user_id/eq','offset','p'];
$collert = TrimX($Field);
if(!empty($collert['start_time'])){
$collert['start_time'] = strtotime($collert['start_time']);
$collert['update_time/gt'] = $collert['start_time'];
unset($collert['start_time']);
}
if(!empty($collert['end_time'])){
$collert['end_time'] = strtotime($collert['end_time']);
$collert['update_time/lt'] = $collert['end_time'];
unset($collert['end_time']);
}
//设置有图片的优先
$collert ['goods_images/order'] = 'desc';
if(!empty($request->user->user_id))
$collert['user_id'] = $request->user->user_id;
else{
$collert['status/eq'] = 1;
$collert['audit_status/eq'] = 1;
}
$GoodsModel = new GoodsModel();
$result = $GoodsModel->FindGoods($collert);
if(!$result)
return $this->Export(ErrorCode(001,1),'没有数据');
return $this->Export(0,'ok',$result);
}
public function AddGoods(Request $request){
$Filed = ['goods_name','brand_name','encap','price','stock','delivery_time','is_auto','goods_images','source',
'currency','ladder_price'];
$collert = TrimX($Filed,true);
$MustFile = [
'goods_name'=> [
'errcode'=>005,'errmsg'=>'请输入商品型号'
], 'brand_name'=>[
'errcode'=>002,'errmsg'=>'请输入品牌'
],'delivery_time'=>[
'errcode'=>003,'errmsg'=>'请输入货期'
],'stock'=>[
'errcode'=>004,'errmsg'=>'请输入库存'
]];
foreach ($MustFile as $k=>$v)
if(empty($collert[$k])) return $this->Export(ErrorCode($v['errcode'],1),$v['errmsg']);
$collert['user_id'] = $request->user->user_id;
$GoodsModel = new GoodsModel();
$result = $GoodsModel->AddGoods($collert);
if($result === false)
return $this->Export(ErrorCode(001,5),'新增失败');
if($result !== true)
return $this->Export(ErrorCode(006,1),'新增失败');
return $this->Export(0,'新增成功');
}
public function SaveGoods($request){
$Filed = ['goods_name','brand_name','encap','price','stock','delivery_time','is_auto','goods_images',
'currency','ladder_price','goods_id'];
$collert = TrimX($Filed);
if(empty($collert['goods_id'])) return $this->Export(ErrorCode(010,1),'请选择要编辑的商品');
$GoodsModel = new GoodsModel();
$result = $GoodsModel ->GoodsInfo($collert['goods_id']);
if(!$result || empty($result[$collert['goods_id']]))
return $this->Export(ErrorCode(002,5),'没有查找到这个型号');
if($result[$collert['goods_id']]['user_id'] != $request->user->user_id)
return $this->Export(ErrorCode(8,1),'没有编辑这个商品的权限');
$result = $GoodsModel->SaveGoods($collert);
if($result === false)
return $this->Export(ErrorCode(003,5),'编辑失败');
if($result !== true)
return $this->Export(ErrorCode(9,1),'编辑失败');
return $this->Export(0,'ok','新增成功');
}
public function GoodsStatus(Request $request){
$collert = TrimX(['goods_id','status']);
$MustField = ['goods_id'=>'未选择商品','status'=>'未选择操作状态'];
foreach ($MustField as $k=>$v)
if(empty($collert[$k]))
return $this->Export(ErrorCode(004,1),$v);
$MustFile = [
'goods_id'=> [
'errcode'=>010,'errmsg'=>'请选择商品'
], 'status'=>[
'errcode'=>011,'errmsg'=>'未选择操作状态'
]];
foreach ($MustFile as $k=>$v)
if(empty($collert[$k])) return $this->Export(ErrorCode($v['errcode'],1),$v['errmsg']);
$Url = config('website.GoodsInfoUrl').'/goods/status';
$collert['user_id'] = $request->user->user_id;
$result = reportCurl($Url,$collert,true);
$result = json_decode($result,true);
if(!isset($result['errcode']) || empty($result['data']))
return $this->Export(ErrorCode(004,5),'操作失败');
if($result['errcode'] !==0 )
return $this->Export(ErrorCode(005,5),'数据异常,操作失败');
if(is_string($collert['goods_id'])){
if(empty($result['data'][$collert['goods_id']]) && $result['data'][$collert['goods_id']] !==true )
return $this->Export(ErrorCode(006,5),'操作失败');
return $this->Export(0,'操作成功');
}else{
$Fail=0;
$su=0;
foreach ($collert['goods_id'] as $k=>$v){
if(empty($result['data'][$v]) || $result['data'][$v] !==true )
$Fail++;
else $su++;
}
if($su > 0){
if($Fail === 0) return $this->Export(0,'操作成功');
else return $this->Export(0,'操作成功数量:'.$su.',操作失败数量:'.$Fail,['data'=>$result['data']]);
} else{
return $this->Export(ErrorCode(007,5),'操作失败',['data'=>$result['data']]);
}
}
}
public function MysqlGoodsCount(Request $request){
$data['count']['mygoods'] = 0;
$data['count']['newadd'] = 0;
$data['count']['imperfect'] = 0;
$map['user_id/eq'] = $request->user->user_id;
$Url = config('website.ES_URL').'/search/get_data';
$result = reportCurl($Url,$map,true);
$result = json_decode($result,true);
if(!empty($result['data']['total']))
$data['count']['mygoods'] = $result['data']['total'];
$map['add_time/gt'] = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y'));//本周0点
$result = json_decode(reportCurl($Url,$map,true),true);
if(!empty($result['data']['total']))
$data['count']['newadd'] = $result['data']['total'];
unset($map['add_time/gt']);
$map['goods_images/eq'] = 2;//1是有图,2是没图
$result = json_decode(reportCurl($Url,$map,true),true);
if(!empty($result['data']['total']))
$data['count']['imperfect'] = $result['data']['total'];
return $this->Export(0,'ok',$data);
}
public function UploadGoods(Request $request)
{
$file = $request->file('file');
if($file -> isValid()) {
$realPath = $file -> getRealPath();
$data['user_id'] = $request->user->user_id;
$Model = new UploadGoodsModel();
$ID = 0;
$result = $Model->UploadGoods($data,$realPath,$ID);
if(!$result)
return $this->Export(ErrorCode(8,5),'上传失败');
if($result !== true)
return $this->Export(ErrorCode(010,1),'上传失败');
$Url = config('website.GoodsInfoUrl').'/goods/task';
$map['user_id'] = $request->user->user_id;
$map['id'] = $ID;
$result = reportCurl($Url,$map,true);
$result = json_decode($result,true);
if(!isset($result['errcode']) || $result['errcode'] !== 0)
return $this->Export(ErrorCode(9,5),'推送任务失败,请联系客服处理');
return $this->Export(0,'上传成功,请等待处理结果');
}else
return $this->Export(ErrorCode(011,1),'没有上传文件');
}
public function UploadGoodsList(Request $request){
$collert = TrimX(['start_time','end_time','limit']);
if(!empty($collert['start_time'])){
$collert['start_time'] = strtotime($collert['start_time']);
$collert['update_time/gt'] = $collert['start_time'];
unset($collert['start_time']);
}
if(!empty($collert['end_time'])){
$collert['end_time'] = strtotime($collert['end_time']);
$collert['update_time/lt'] = $collert['end_time'];
unset($collert['end_time']);
}
if(!empty($collert['limit'])){
$limit = $collert['limit'];
unset($collert['limit']);
}else $limit = 10;
$collert['user_id'] = $request->user->user_id;
$Model = new UploadGoodsModel();
$result = $Model->UploadGoodsList($collert,$limit);
return $this->Export(0,'ok',$result);
}
}
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}
......@@ -40,7 +40,7 @@ class IntegralsController extends Controller
$userIntegral = $userIntegralService->getUserIntegral(['id' => $userId]);
if ($userIntegral) {
$result['integral'] = $userIntegral['data']['integral'];
$result['code'] = 'RD' . $userId;
$result['code'] = 'RDD' . $userId;
}
return $this->Export(0, 'ok', $result);
......
......@@ -7,12 +7,48 @@ use Common\Model\RedisModel;
class IntegralService
{
const INTEGRAL_TYPE_INVITE_FRIEND = 1;
const INTEGRAL_TYPE_UPLOAD_GOODS = 2;
const INTEGRAL_TYPE_INTEGRAL_CODE = 3;
const INTEGRAL_TYPE_SHARE = 4;
const INTEGRAL_TYPE_OFFER = 5;
const INTEGRAL_TYPE_CHECK_IN = 6;
public function getIntegralList($map = [])
{
$url = config('website.BaseUrl') . '/integrals/list';
$result = reportCurl($url, $map, true);
$result = json_decode($result, true);
//针对红包码兑换这块
//因为红包码兑换只能操作一次,所以要给一个单独的状态值告诉前端是否已经兑换过红包了
if (isset($result['data'])) {
foreach ($result['data'] as $key => $value) {
switch ($value['id']) {
case self::INTEGRAL_TYPE_INVITE_FRIEND:
$result['data'][$key]['button_text'] = '去邀请';
break;
case self::INTEGRAL_TYPE_UPLOAD_GOODS:
$result['data'][$key]['button_text'] = '去上传';
break;
case self::INTEGRAL_TYPE_INTEGRAL_CODE:
$result['data'][$key]['button_text'] = '去兑换';
break;
case self::INTEGRAL_TYPE_SHARE:
$result['data'][$key]['button_text'] = '去分享';
break;
case self::INTEGRAL_TYPE_OFFER:
$result['data'][$key]['button_text'] = '去报价';
break;
case self::INTEGRAL_TYPE_CHECK_IN:
$result['data'][$key]['button_text'] = '签到';
break;
}
}
}
return $result;
}
}
\ No newline at end of file
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 sign in to comment