1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- <?php
- namespace app\index\controller;
- use app\index\model\BuyCarModel;
- use app\index\model\ProductCategoryModel;
- use app\index\model\ProductModel;
- use app\index\model\ProductOrderDetailModel;
- use app\index\model\ProductOrderModel;
- use app\index\model\UserAddressModel;
- use app\index\service\HelperService;
- use app\index\service\ProductService;
- class Product extends CmsController
- {
- /**
- * 添加商品接口
- */
- public function addProduct(){
- $param_list = [
- 'category_id'=>'number',
- 'product_number'=>'string',
- 'product_name'=>'string',
- 'market_price'=>'number',
- 'sales_price'=>'number',
- 'remain_num'=>'number',
- 'product_value_id'=>'array',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $id = $ProductService->addProduct($this->post);
- $this->returnJson(['id'=>$id]);
- }
- /**
- * 添加商品分类的接口
- */
- public function addProductCategory(){
- $param_list = [
- 'category_name'=>'string',
- 'parent_id'=>'int',
- ];
- HelperService::diffParam($param_list,$this->post);
- if(isset($this->post['category_img']) && is_array($this->post['category_img'])){
- $category_img = json_encode($this->post['category_img']);
- }
- $data = [
- 'category_name'=>$this->post['category_name'],
- 'parent_id'=>$this->post['parent_id'],
- 'category_img'=>$category_img,
- 'status'=>0
- ];
- $ProductService = new ProductService();
- $product = $ProductService->getProductCategoryByCondition(['category_name'=>$this->post['category_name']]);
- if($product){
- $this->returnJson('category_name is duplicate');
- }
- $id=$ProductService->addProductCategory($data);
- $this->returnJson(['id'=>$id]);
- }
- /**
- * 更新商品分类接口
- */
- public function upProductCategory(){
- $param_list = [
- 'category_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $update_list = ['category_id','category_name','parent_id','status','category_img'];
- $data = [];
- foreach($this->post as $key=>$item){
- if(!in_array($key,$update_list)){
- continue;
- }
- $data[$key] = $item;
- }
- if(isset($this->post['category_img']) && is_array($this->post['category_img'])){
- $data['category_img'] = json_encode($this->post['category_img']);
- }
- $ProductService = new ProductService();
- $row=$ProductService->upProductCategory($data);
- $this->returnJson(['row'=>$row]);
- }
- public function addProductAttr(){
- $param_list = [
- 'attr_name'=>'string',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $id=$ProductService->addProductAttr($this->post);
- $this->returnJson(['id'=>$id]);
- }
- public function upProductAttr(){
- $param_list = [
- 'attr_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $row=$ProductService->upProductAttr($this->post);
- $this->returnJson(['row'=>$row]);
- }
- public function addProductAttrValue(){
- $param_list = [
- 'attr_id'=>'number',
- 'value_name'=>'string',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $id=$ProductService->addProductAttrValue($this->post);
- $this->returnJson(['id'=>$id]);
- }
- public function upProductAttrValue(){
- $param_list = [
- 'product_value_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $row=$ProductService->upProductAttrValue($this->post);
- $this->returnJson(['row'=>$row]);
- }
- public function addProductImg(){
- $param_list = [
- 'product_id'=>'number',
- 'img'=>'string',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $id=$ProductService->addProductImg($this->post);
- $this->returnJson(['id'=>$id]);
- }
- public function upProductImg(){
- $param_list = [
- 'id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $ProductService = new ProductService();
- $row=$ProductService->upProductImg($this->post);
- $this->returnJson(['row'=>$row]);
- }
- /**
- * 获取分类列表
- */
- public function getCategoryList(){
- $productCategoryModel = new ProductCategoryModel();
- $productCategory = $productCategoryModel->getList(['status'=>0]);
- $this->returnJson($productCategory);
- }
- /**
- * 根据分类id获取分类信息
- */
- public function getCategoryInfoById(){
- $param_list = [
- 'category_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $productCategoryModel = new ProductCategoryModel();
- $productCategory = $productCategoryModel->where([
- 'category_id'=>$this->post['category_id'],
- ])->find();
- $this->returnJson($productCategory);
- }
- /**
- * 获取当前分类下的产品列表
- */
- public function getProductListByCategoryId(){
- $param_list = [
- 'category_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $productModel = new ProductModel();
- if(!isset($this->post['product_id'])){
- $productList = $productModel->getList(['category_id'=>$this->post['category_id'],'remain_num'=>['gt',0],'status'=>0],'add_time desc',300);
- }else{
- $product_id = $this->post['product_id'];
- $productList = $productModel->getList(['category_id'=>$this->post['category_id'],'remain_num'=>['gt',0],'status'=>0],"product_id <> {$product_id},add_time desc");
- }
- $this->returnJson($productList);
- }
- /**
- * 将产品加入购物
- */
- public function addCar(){
- $param_list = [
- 'product_id'=>'number',
- 'user_id'=>'number',
- 'num'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $buyCar = $buyCarModel->getOne(['user_id'=>$this->post['user_id'],'product_id'=>$this->post['product_id']]);
- if(empty($buyCar)){
- $data = [
- 'user_id'=>$this->post['user_id'],
- 'product_id'=>$this->post['product_id'],
- 'num'=>$this->post['num'],
- 'add_time'=>time()
- ];
- $id = $buyCarModel->addInfo($data);
- }else{
- $id = $buyCarModel->upInfo(['id'=>$buyCar['id'],'user_id'=>$this->post['user_id'],'num'=>$buyCar['num']],['num'=>$this->post['num']+$buyCar['num']]);
- }
- $this->returnJson(['id'=>$id]);
- }
- /**
- * 将产品自增
- */
- public function incCar(){
- $param_list = [
- 'product_id'=>'number',
- 'user_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $buyCar = $buyCarModel->getOne(['user_id'=>$this->post['user_id'],'product_id'=>$this->post['product_id']]);
- if(empty($buyCar)){
- $data = [
- 'user_id'=>$this->post['user_id'],
- 'product_id'=>$this->post['product_id'],
- 'num'=>1,
- 'add_time'=>time()
- ];
- $id = $buyCarModel->addInfo($data);
- }else{
- $id = $buyCarModel->where(['id'=>$buyCar['id']])->setInc('num',1);
- }
- $this->returnJson(['id'=>$id]);
- }
- /**
- * 获取购物车列表
- */
- public function getCarInfo(){
- $param_list = [
- 'user_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $list = $buyCarModel->getCarAndProductInfo(['user_id'=>$this->post['user_id'],'buy_car.status'=>0]);
- $priceList = [];
- $total_num = 0;
- foreach($list as $item){
- $total_num += $item['num'];
- $priceList[] = $item['sales_price'] * $item['num'];
- }
- $data = [
- 'count'=>$total_num,
- 'total_price'=>array_sum($priceList)
- ];
- $this->returnJson($data);
- }
- /**
- * 获取购物车列表
- */
- public function getCarList(){
- $param_list = [
- 'user_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $list = $buyCarModel->getCarAndProductInfo(['user_id'=>$this->post['user_id'],'buy_car.status'=>0]);
- $priceList = [];
- foreach($list as $item){
- $priceList[] = $item['sales_price'] * $item['num'];
- }
- $data = [
- 'total_price'=>array_sum($priceList),
- 'list'=>$list
- ];
- $this->returnJson($data);
- }
- /**
- *批量查询勾选的商品
- */
- public function getCarListByProductIds(){
- $param_list = [
- 'user_id'=>'number',
- 'productIds'=>'array',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $list = $buyCarModel->getCarAndProductInfo([
- 'buy_car.user_id'=>$this->post['user_id'],
- 'buy_car.status'=>0,
- 'buy_car.product_id'=>['in',$this->post['productIds']]
- ]);
- $priceList = [];
- foreach($list as $item){
- $priceList[] = $item['sales_price'] * $item['num'];
- }
- $data = [
- 'total_price'=>array_sum($priceList),
- 'list'=>$list,
- ];
- $this->returnJson($data);
- }
- /**
- *批量更新勾选的商品
- */
- public function updateCarByProductIds(){
- $param_list = [
- 'user_id'=>'number',
- 'productIdAndNum'=>'array',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $row = 0;
- foreach($this->post['productIdAndNum'] as $product_id=>$num){
- $row += $buyCarModel->upInfo(['product_id'=>$product_id,'user_id'=>$this->post['user_id']],['num'=>$num]);
- }
- $this->returnJson(['row'=>$row]);
- }
- /**
- * 批量删除被勾选的商品
- */
- public function delCarBatch(){
- $param_list = [
- 'user_id'=>'number',
- 'product_ids'=>'array',
- ];
- HelperService::diffParam($param_list,$this->post);
- $buyCarModel = new BuyCarModel();
- $row = $buyCarModel->where([
- 'user_id'=>$this->post['user_id'],
- 'product_id'=>['in',$this->post['product_ids']]
- ])->delete();
- $this->returnJson(['row'=>$row]);
- }
- /**
- * 保存 用户收货地址
- */
- public function saveAddress(){
- $param_list = [
- 'user_id'=>'number',
- 'name'=>'string',
- 'mobile'=>'mobile',
- 'city'=>'string',
- 'address'=>'string',
- 'address_name'=>'string',
- ];
- HelperService::diffParam($param_list,$this->post);
- $data = [
- 'user_id' => $this->post['user_id'],
- 'name' => $this->post['name'],
- 'mobile' => $this->post['mobile'],
- 'city' => $this->post['city'],
- 'address' => $this->post['address'],
- 'address_name' =>$this->post['address_name'],
- 'status' => 0
- ];
- $userAddressModel = new UserAddressModel();
- if(isset($this->post['address_id']) && !empty($this->post['address_id']) && is_numeric($this->post['address_id'])) {
- $where['address_id'] = $this->post['address_id'];
- $row = $userAddressModel->upInfo($where,$data);
- $this->returnJson(['row'=>$row]);
- }else{
- $data['add_datetime'] = date('Y-m-d H:i:s');
- $id = $userAddressModel->addInfo($data);
- $this->returnJson(['id'=>$id]);
- }
- }
- /**
- * 删除 用户的收货地址
- */
- public function delAddress(){
- $param_list = [
- 'address_id'=>'number',
- 'user_id'=>'number'
- ];
- HelperService::diffParam($param_list,$this->post);
- $userAddressModel = new UserAddressModel();
- $row = $userAddressModel
- ->where([
- 'address_id'=>$this->post['address_id'],
- 'user_id'=>$this->post['user_id']
- ])->delete();
- $this->returnJson(['row'=>$row]);
- }
- /**
- * 将收货地址设置为默认地址
- */
- public function setDefaultAddress(){
- $param_list = [
- 'user_id'=>'number',
- 'address_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $userAddressModel = new UserAddressModel();
- $where = [
- 'user_id' => $this->post['user_id'],
- 'address_id'=> $this->post['address_id'],
- ];
- $row = 0;
- $res = $userAddressModel->upInfo(['user_id'=>$this->post['user_id']],['default_address'=>0]);
- if($res){
- $row += 1;
- }
- $res = $userAddressModel->upInfo($where,['default_address'=>1]);
- if($res){
- $row += 1;
- }
- $this->returnJson(['row'=>$row]);
- }
- /**
- * 获取默认地址的信息
- */
- public function getDefaultAddress(){
- $param_list = [
- 'user_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $userAddressModel = new UserAddressModel();
- $userAddress = $userAddressModel->getOne([
- 'user_id'=>$this->post['user_id'],
- 'default_address'=>1,
- ]);
- $this->returnJson($userAddress);
- }
- /**
- *通过地址的id获取地址信息
- */
- public function getUserAddressById(){
- $param_list = [
- 'address_id'=>'int',
- ];
- HelperService::diffParam($param_list,$this->post);
- $userAddressModel = new UserAddressModel();
- $userAddress = $userAddressModel->getOne([
- 'address_id'=>$this->post['address_id']
- ]);
- $this->returnJson($userAddress);
- }
- /**
- * 根据用户id获取收货地址的列表
- */
- public function getUserAddressListByUserId(){
- $param_list = [
- 'user_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $userAddressModel = new UserAddressModel();
- $userAddress = $userAddressModel->getList([
- 'user_id'=>$this->post['user_id'],
- ],"default_address desc,address_id desc");
- $this->returnJson($userAddress);
- }
- /**
- * 获取产品的分页列表
- */
- public function getProductPage(){
- $param_list = [
- 'pageSize'=>'number',
- 'page'=>'number',
- 'condition'=>'array',
- ];
- HelperService::diffParam($param_list,$this->post);
- $search_key = ['product_id','category_id','product_name','origin'];
- $condition = $this->post['condition'];
- $where = [];
- foreach($condition as $key=>$item){
- if(!in_array($key,$search_key)){
- continue;
- }
- switch($key){
- case "product_id":
- case "category_id":
- $where[$key] = $item;
- break;
- case 'product_name':
- case 'origin':
- $where[$key] = ['like',"%{$item}%"];
- break;
- }
- }
- $page = $this->post['page'];
- $pageSize = $this->post['pageSize'];
- $page = $page>=1?intval($page):1;
- $pageSize = $pageSize>2?intval($pageSize):2;
- $productModel = new ProductModel();
- if($where) {
- $productCount = $productModel->where($where)->count();
- $productList = $productModel->where($where)->page($page, $pageSize)->select();
- }else{
- $productCount = $productModel->count();
- $productList = $productModel->page($page, $pageSize)->select();
- }
- $data = [
- 'count' => $productCount,
- 'list'=>$productList
- ];
- $this->returnJson($data);
- }
- /**
- * 获取产品订单列表
- */
- public function getProductOrderPageByType(){
- $param_list = [
- 'page'=>'number',
- 'pageSize'=>'number',
- 'status'=>'int',
- ];
- HelperService::diffParam($param_list,$this->post);
- if(!in_array($this->post['status'],[0,1,2,3,10])){
- $this->returnJson('',400,'status is error');
- }
- //判断要查询的订单
- $where = ['status'=>$this->post['status']];
- if($this->post['status'] == 10){
- //全部订单
- $where = [];
- }
- //可选条件user_id
- $user_id = isset($this->post['user_id'])?$this->post['user_id']:0;
- if(!empty($user_id) && is_numeric($user_id)){
- $where['user_id'] = $this->post['user_id'];
- }
- //可选条件
- $condition = isset($this->post['condition'])?$this->post['condition']:[];
- if(!empty($condition) && is_array($condition)){
- foreach($condition as $key=>$value){
- switch($key){
- case 'order_no':
- case 'pay_style':
- case 'logistic_company':
- case 'logistic_number':
- $where[$key] = $value;
- break;
- case 'add_time':
- case 'pay_time':
- //确保是时间戳
- $time = intval($value);
- //日期当天的数据
- $where[$key] = ['between',[$time,$time+86400]];
- break;
- }
- }
- }
- $page = $this->post['page'] >1?$this->post['page']:1;
- $pageSize = $this->post['pageSize'] >1?$this->post['pageSize']:2;
- $productOrderModel = new ProductOrderModel();
- $res = $productOrderModel->getPage($where,"order_id desc",$page,$pageSize);
- $this->returnJson($res);
- }
- /**
- * 修改
- */
- /**
- * 无额外属性的产品添加接口
- */
- public function saveProductNotAttr(){
- $param_list = [
- 'category_id'=>'number',
- 'product_name'=>'string',
- 'product_number'=>'',
- 'market_price'=>'int',
- 'sales_price'=>'int',
- 'remain_num'=>'int',
- ];
- HelperService::diffParam($param_list,$this->post);
- $productModel = new ProductModel();
- $data = [
- 'category_id'=>$this->post['category_id'],
- 'product_number'=>$this->post['product_number'],
- 'product_name'=>$this->post['product_name'],
- 'market_price'=>$this->post['market_price'],
- 'sales_price'=>$this->post['sales_price'],
- 'remain_num'=>$this->post['remain_num'],
- 'add_time'=>time(),
- 'add_datetime'=>date('Y-m-d H:i:s'),
- 'content'=>isset($this->post['content'])?$this->post['content']:'',
- 'weight'=>isset($this->post['weight'])?$this->post['weight']:'',
- 'origin'=>isset($this->post['origin'])?$this->post['origin']:'',
- 'Unit'=>isset($this->post['Unit'])?$this->post['Unit']:'',
- 'img'=>isset($this->post['img'])?$this->post['img']:'',
- ];
- if(isset($this->post['product_id'])) {
- $product_id = intval($this->post['product_id'])>0?$this->post['product_id']:0;
- $row = $productModel->upInfo(['product_id'=>$product_id],$data);
- $this->returnJson(['row' => $row]);
- }else{
- $id = $productModel->addInfo($data);
- $this->returnJson(['id' => $id]);
- }
- }
- /**
- * 根据productId获取ProductInfo
- */
- public function getProductDetailById(){
- $param_list = [
- 'product_id'=>'number'
- ];
- HelperService::diffParam($param_list,$this->post);
- $productModel = new ProductModel();
- $product = $productModel->where(['product_id'=>$this->post['product_id']])->find();
- $this->returnJson($product);
- }
- /**
- * 根据productId修改产品信息
- */
- public function upProductInfoByProductId(){
- $param_list = [
- 'product_id'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- $data = [
- 'status'=>isset($this->post['status'])?$this->post['status']:0,
- ];
- $productModel = new ProductModel();
- $row = $productModel->upInfo(['product_id'=>$this->post['product_id']],$data);
- $this->returnJson(['row'=>$row]);
- }
- /**
- * 通过条件获取订单信息
- */
- public function getUserOrderByType(){
- $param_list = [
- 'user_id'=>'number',
- 'status'=>'int'
- ];
- HelperService::diffParam($param_list,$this->post);
- if(!in_array($this->post['status'],[0,1,2,3,4,10])){
- $this->returnJson([],400,'status is error');
- }
- $params = [];
- $params['user_id'] = $this->post['user_id'];
- if($this->post['status']!=10){
- $params['status'] = $this->post['status'];
- }
- $productOrderModel = new ProductOrderModel();
- $productOrder = $productOrderModel->getProductOrder($params);
- $this->returnJson($productOrder);
- }
- /**
- * 用户每种类型订单的数量
- */
- public function getUserOrderCountByType(){
- $param_list = [
- 'user_id'=>'number',
- 'status'=>'int'
- ];
- HelperService::diffParam($param_list,$this->post);
- if(!in_array($this->post['status'],[0,1,2,3,4,10])){
- $this->returnJson([],400,'status is error');
- }
- $params = [];
- $params['user_id'] = $this->post['user_id'];
- if($this->post['status']!=10){
- $params['status'] = $this->post['status'];
- }
- $productOrderModel = new ProductOrderModel();
- $productOrderCount = $productOrderModel->getProductOrderCount($params);
- $this->returnJson($productOrderCount);
- }
- /**
- * 根据订单编号或许订单详情
- */
- public function getOrderByOrderNo(){
- $param_list = [
- 'order_no'=>'string'
- ];
- HelperService::diffParam($param_list,$this->post);
- $params = [];
- $params['order_no'] = $this->post['order_no'];
- $productOrderModel = new ProductOrderModel();
- $productOrder = $productOrderModel->getOne($params);
- $order_no = isset($productOrder['order_no'])?$productOrder['order_no']:0;
- $productOrderDetailModel = new ProductOrderDetailModel();
- $productOrderDetail = $productOrderDetailModel->getList(['order_no'=>$order_no],'',1000);
- if($productOrder){
- $productOrder['detail'] = $productOrderDetail;
- }
- $this->returnJson($productOrder);
- }
- /**
- * 前台用户取消订单(暂时不用这个接口,因为和功能有点重复)
- */
- private function userCancelOrder(){
- $param_list = [
- 'order_no'=>'string',
- 'user_id'=>'number'
- ];
- HelperService::diffParam($param_list,$this->post);
- $orderModel = new ProductOrderModel();
- $orderModel->upInfo([
- 'order_no'=>$this->post['order_no'],
- 'user_id'=>$this->post['user_id']
- ],['status'=>3]);
- $this->returnJson('success');
- }
- /**
- * 后台需要订单
- */
- public function saveOrderStatus(){
- $param_list = [
- 'order_no'=>'string',
- 'status'=>'number',
- ];
- HelperService::diffParam($param_list,$this->post);
- if(!in_array($this->post['status'],[0,1,2,3,4])){
- $this->returnJson([],400,'status is error');
- }
- $orderModel = new ProductOrderModel();
- $orderModel->upInfo(
- ['order_no'=>$this->post['order_no']],
- ['status'=>$this->post['status']]
- );
- $this->returnJson('success');
- }
- /**
- * 保存订单信息
- */
- public function saveOrderInfo(){
- $param_list = [
- 'order_no'=>'string',
- 'status'=>'int'
- ];
- HelperService::diffParam($param_list,$this->post);
- $data = [];
- if(isset($this->post['logistic_company_name'])){
- $data['logistic_company_name'] = $this->post['logistic_company_name'];
- }
- if(isset($this->post['back_note'])){
- $data['back_note'] = $this->post['back_note'];
- }
- if(isset($this->post['logistic_number'])){
- $data['logistic_number'] = $this->post['logistic_number'];
- }
- if(!in_array($this->post['status'],[0,1,2,3,4])){
- $this->returnJson([],400,'status is error');
- }
- $data['status'] = $this->post['status'];
- $orderModel = new ProductOrderModel();
- $orderModel->upInfo(['order_no'=>$this->post['order_no']],$data);
- $this->returnJson('success');
- }
- /**
- * 提交订单信息
- */
- public function PayOrder(){
- $param_list = [
- 'user_id'=>'number',
- 'productIds'=>'array',
- 'send_style'=>'int',
- 'pay_style'=>'int',
- ];
- HelperService::diffParam($param_list,$this->post);
- $productService = new ProductService();
- $orderModel = new ProductOrderModel();
- $order_no = $this->createOrderNum();
- $total_price = $productService->getOrderPriceByProductIds($order_no,$this->post['productIds'],$this->post['user_id']);
- if(empty($total_price)){
- HelperService::returnJson(['code'=>400,'msg'=>'Payorder is error']);
- }
- switch($this->post['send_style']){
- //快递方式
- case 0:
- $order =[
- 'order_no'=>$order_no,
- 'address_id'=>$this->post['address_id']?:0,
- 'add_time'=>time(),
- 'user_id'=>$this->post['user_id'],
- 'total_price'=> $total_price,
- 'pay_style'=>$this->post['pay_style'],
- 'send_style'=>$this->post['send_style'],
- 'note'=>$this->post['note']?:'',
- 'status'=>0
- ];
- $order_id = $orderModel->addInfo($order);
- if($order_id === false){
- HelperService::returnJson(['code'=>400,'msg'=>'insert order fail']);
- }
- break;
- //自提方式
- case 1:
- $order =[
- 'order_no'=>$order_no,
- 'address_id'=>$this->post['address_id']?:0,
- 'add_time'=>time(),
- 'add_date'=>date('Y-m-d'),
- 'user_id'=>$this->post['user_id'],
- 'total_price'=> $total_price,
- 'pay_style'=>$this->post['pay_style'],
- 'send_style'=>$this->post['send_style'],
- 'note'=>$this->post['note']?:'',
- 'status'=>0,
- 'get_datetime'=>$this->post['get_datetime'],
- ];
- $order_id = $orderModel->addInfo($order);
- if($order_id === false){
- HelperService::returnJson(['code'=>400,'msg'=>'insert order fail']);
- }
- break;
- default:
- HelperService::returnJson(['code'=>400,'msg'=>'send_style is error']);
- break;
- }
- $this->returnJson(['order_no'=>$order_no]);
- }
- /**
- *商品每日订单数量
- */
- public function ProductOrderDayNum(){
- $param = $this->request->param();
- $end_date = isset($param['end_date'])?strtotime($param['end_date']):strtotime("-1 seconds",strtotime(date('Y-m-d')));
- $start_date = isset($param['start_date'])?strtotime($param['start_date']):0;
- //控制时间,以免增加服务器压力
- if(empty($start_date) || $end_date-$start_date>86400*20){
- $start_date = $end_date-86400*20;
- }
- $productOrderModel = new ProductOrderModel();
- $productOrder = $productOrderModel
- ->field('count(order_id) as total_count,add_date')
- ->where(['add_date'=>['between',[date('Y-m-d',$start_date),date('Y-m-d',$end_date)]]])->group('add_date')->cache(3600*2)->select();
- $this->returnJson($productOrder);
- }
- /**
- *订单总数量
- */
- public function totalOrderNum(){
- $productOrderModel = new ProductOrderModel();
- $productOrder = $productOrderModel->cache(10)->count();
- $this->returnJson(['count'=>$productOrder]);
- }
- }
|