errorResponse(lang('request_method_incorrect')); } try { $platform_goods_code = input('platform_goods_code'); $supplier_goods_code = input('supplier_goods_code'); $condition['poc.status'] = 0;// $p = input('p', 1); $_GET['p'] = $p; $other['page_size'] = input('page_size', 20); $order = 'id asc'; $count = \app\supplier\model\PublishOrder::alias('po') ->alias('po') ->join('web_publish_order_cancel poc', 'po.id=poc.publish_order_id') ->where($condition) ->count(); $list = \app\supplier\model\PublishOrder::alias('po') ->alias('po') ->join('web_publish_order_cancel poc', 'po.id=poc.publish_order_id') ->field("poc.id as cancel_id,po.id,supplier_goods_code,publish_order_code,first_cate_code,second_cate_code,three_cate_code,public_type,brand_code,poc.add_time,publish_status,update_time,goods_title_cn,(select url from web_publish_order_picture where publish_order_id=po.id order by id asc limit 1) as picture,poc.status,poc.remark,poc.reason_id")->where($condition)->order($order)->page($p, $other['page_size'])->select()->toArray(); $other['count'] = $count; if ($list) { $categorylist = get_category(); $categorylist = datalist($categorylist, 'cate_code', '', FALSE); foreach ($list as &$item) { $item['first_cate_name'] = $categorylist[$item['first_cate_code']]['cate_name']; $item['second_cate_name'] = $categorylist[$item['second_cate_code']]['cate_name']; $item['three_cate_name'] = $categorylist[$item['three_cate_code']]['cate_name']; $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']); } $result['list'] = $list; $result['other'] = $other; return $this->successResponse($result); } else { return $this->errorResponse(lang('no_data_found')); } } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } /** * 取消刊登审核 * @return array|int[] */ public function reviewPublishOrder() { // 开始数据库事务 Db::startTrans(); try { if (!Request::isPost()) { throw new Exception(lang('request_method_incorrect')); } $publish_order_id = input('post.publish_order_id'); $cancel_id = input('post.cancel_id'); if (is_numeric($cancel_id)) { $status = input('post.status'); //更新数据 $info = Db::name('publish_order_cancel')->field('id,status')->where('id', $cancel_id)->find(); if (!$info) { return $this->errorResponse(lang('request_method_incorrect')); } if($info['status']==1){ return $this->errorResponse('该申请已审核通过,不能重复审核'); } if ($status == 1) { Db::name('publish_order_cancel')->where('id', $cancel_id)->update(['status' => 1]); Db::name('publish_order')->where('id', $publish_order_id)->update(['publish_status' => 0, 'audit_status' => 1, 'review_comments' => '']); $message = '操作成功,审核通过'; } else { $comments = trim(input('comments')); if (!$comments) { return $this->errorResponse('请填写审核不通过原因'); } Db::name('publish_order_cancel')->where('id', $cancel_id)->update(['status' => 1, 'comments' => $comments]); $message = '操作成功,审核不通过'; } // 提交事务 Db::commit(); return $this->successResponse($message); } else { return $this->errorResponse(lang('request_method_incorrect')); } } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 创建商品 * @return string */ public function create() { //////// $id = input('id'); if (!is_numeric($id)) { $this->redirect(url('/supplier/cancelPublishOrder/index')->build()); } $cancel_id = input('cancel_id'); $other['id'] = $id; $other['cancel_id'] = $cancel_id; View::assign('other', $other); return View::fetch(); } public function getGoodsInfo() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } $supplier_goods_code = input('supplier_goods_code'); if (!is_numeric($supplier_goods_code)) { return $this->errorResponse(lang('invalid_id')); } try { $where = [ 'supplier_goods_code' => $supplier_goods_code, ]; $info = Db::name('goods')->field('id,first_cate_code,second_cate_code,three_cate_code,brand_code')->where($where)->find(); if ($info['three_cate_code']) { $info['cate_code'] = [$info['first_cate_code'], $info['second_cate_code'], $info['three_cate_code']]; } $info['goods_purpose'] = json_decode($info['goods_purpose'], TRUE); //////获取描述标题数据///////// $where_other = [ 'goods_id' => $info['id'], ]; $goods_desc = Db::name('goods_desc')->field('goods_title_en,goods_title_cn')->where($where_other)->find(); //获取描述内容数据 $goods_desc_content = Db::name('goods_desc_content')->field('goods_desc_en,goods_desc_cn')->where($where_other)->find(); //////////////// $result['info'] = $info; $result['goods_desc'] = $goods_desc; $result['goods_desc_content'] = $goods_desc_content; return $this->successResponse($result); } catch (Exception $e) { return $this->errorResponse($e->getMessage()); } } /** * 获取商品分销信息 * @return array|int[] */ public function getGoodsDisInfo() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } try { $supplier_goods_code = input('supplier_goods_code'); $condition['g.istemp'] = 1;//编辑过的商品 if ($supplier_goods_code) { $condition['g.supplier_goods_code'] = $supplier_goods_code; } $info = \app\supplier\model\Goods::alias('g') ->join('goods_desc gd', 'g.id=gd.goods_id') ->join('goods_desc_content gdc', 'g.id=gdc.goods_id') ->field("g.id,g.warehouse_mode,g.sales_form,g.supplier_goods_code,g.platform_goods_code,g.goods_purpose,g.add_time,g.status,g.publish_status,g.whether_dis,g.is_limit_dis_platform,gd.goods_title_cn,gd.goods_title_en,gd.goods_keyword_en,gd.goods_keyword_cn,g.first_cate_code,g.second_cate_code,g.three_cate_code,g.docking_way,g.price_method,g.freight_attr_code,g.is_tort,g.is_stop_buy,g.recommend_man,gdc.goods_desc_en,gdc.goods_desc_cn")->where($condition)->find(); if ($info) { $categorylist = get_category(); $categorylist = datalist($categorylist, 'cate_code', '', FALSE); $info['first_cate_name'] = $categorylist[$info['first_cate_code']]['cate_name']; $info['second_cate_name'] = $categorylist[$info['second_cate_code']]['cate_name']; $info['three_cate_name'] = $categorylist[$info['three_cate_code']]['cate_name']; $info['attr_name'] = Db::name('goods_freight_attr')->where('attr_code', $info['freight_attr_code'])->value('attr_name'); $info['goods_keyword_en'] = $info['goods_keyword_en'] ? json_decode($info['goods_keyword_en'], TRUE) : []; $info['goods_keyword_cn'] = $info['goods_keyword_cn'] ? json_decode($info['goods_keyword_cn'], TRUE) : []; $info['goodsSpecInfo'] = Db::name('goods_spec')->field('*')->where('goods_id', $info['id'])->find(); $goods_attribute_info = Db::name('goods_attribute')->field('*') ->withAttr('material_main', function ($value, $data) { return Db::name('goods_material')->where('id', $value)->value('material_name'); }) ->withAttr('material_one', function ($value, $data) { return Db::name('goods_material')->where('id', $value)->value('material_name'); }) ->withAttr('material_two', function ($value, $data) { return Db::name('goods_material')->where('id', $value)->value('material_name'); }) ->withAttr('material_three', function ($value, $data) { if ($value) { $value = json_decode($value, TRUE); return Db::name('goods_material')->whereIn('id', $value)->column('material_name'); } else { return []; } }) ->where('goods_id', $info['id'])->find(); $info['goodsAttributeInfo'] = $goods_attribute_info; $info['goodsAttributExtendList'] = Db::name('goods_attribute_extend')->field('*')->where('goods_id', $info['id'])->select()->toArray(); $info['goodsRetailPriceLimitList'] = GoodsRetailPriceLimit::field('*')->where('goods_id', $info['id']) ->withAttr('sale_country_code', function ($value, $data) { return Db::name('stock_country')->where('id', $value)->value("CONCAT(country_code,' ',country)"); }) ->withAttr('sales_platform', function ($value, $data) { return Db::name('sales_platform')->where('id', $value)->value("platform_name"); }) ->order('id asc')->select()->toArray();/// $info['goodsLabelList'] = GoodsLabel::field('label_type,goods_label')->where('goods_id', $info['id'])->order('id asc')->select()->toArray();/// if ($info['is_limit_dis_platform'] == 1) { $info['goodsLimitDisPlatformList'] = Db::name('goods_limit_dis_platform') ->alias('a') ->join('dis_platform b', 'a.dis_platform = b.id') ->field('b.platform_name')->where('goods_id', $info['id'])->order('a.id asc')->select()->toArray();/// } else { $info['goodsLimitDisPlatformList'] = []; } $result['info'] = $info; ///分销区域// $disAreaList = Db::name('goods_distribution_area') ->alias('gda') ->join('distribution_area da', 'da.id=gda.distribution_area_id') ->field("gda.one_shipment,gda.distribution_area_id")->where('gda.goods_id', $info['id'])->where('gda.whether_dis', 1)->withAttr('one_shipment', function ($value, $data) { return $value == 1 ? '一件代发' : ''; })->withAttr('distribution_area_id', function ($value, $data) { return $this->getDisArea($value); })->select()->toArray(); $result['disAreaList'] = $disAreaList; //分销库存 $disStockList = Db::name('goods_distribution_area_stock') ->alias('gdas') ->join('third_party_stock tps', 'tps.id=gdas.third_party_stock_id') ->field("gdas.distribution_area_id,gdas.supplier_stock_amount,gdas.platform_stock_amount,gdas.goods_distribution_area_id,tps.third_party_stock_name,tps.docking_code,tps.stock_type")->where('gdas.goods_id', $info['id'])->where('gdas.whether_dis', 1) ->withAttr('distribution_area_id', function ($value, $data) { return $this->getDisArea($value); })->select()->toArray(); $result['disStockList'] = $disStockList; //分销价格/// $disPriceList = Db::name('goods_distribution_area_price') ->alias('gdap') ->join('goods_distribution_area gda', 'gda.id=gdap.goods_distribution_area_id') ->join('logistics_product lp', 'lp.id=gdap.logistics_product_id') ->field("gdap.distribution_area_id,gdap.goods_distribution_area_id,lp.product_name_cn,gdap.supply_price,gdap.dis_price,gdap.package_goods_amount,gda.take_effect_time")->where('gdap.goods_id', $info['id'])->where('gda.whether_dis', 1) ->withAttr('distribution_area_id', function ($value, $data) { return $this->getDisArea($value); }) ->withAttr('take_effect_time', function ($value, $data) { return date('Y-m-d H:i:s', $value); })->select()->toArray(); $result['disPriceList'] = $disPriceList; //退货地址列表// $disReturnGoodsList = Db::name('goods_distribution_area') ->alias('gda') ->join('third_party_stock tps', 'tps.id=gda.third_party_stock_id') ->join('third_party_stock_address tpsa', 'tpsa.id=gda.third_party_stock_address_id') ->field("gda.distribution_area_id,tps.third_party_stock_name,tpsa.stock_address,tpsa.stock_city,tpsa.stock_province,tpsa.stock_post_code,tpsa.stock_country_id,tpsa.receive_man,tpsa.tel")->where('gda.goods_id', $info['id'])->where('gda.whether_dis', 1) ->withAttr('distribution_area_id', function ($value, $data) { return $this->getDisArea($value); }) ->withAttr('stock_country_id', function ($value, $data) { return Db::name('stock_country')->where('id', $value)->value('country'); }) ->select()->toArray(); $result['disReturnGoodsList'] = $disReturnGoodsList; return $this->successResponse($result); } else { return $this->errorResponse(lang('no_data_found')); } } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } /** * 获取商品图片列表 * @return array|int[] */ public function getGoodsPictureList() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } try { $goods_id = input('goods_id'); $picture_type = input('picture_type'); if (is_array($picture_type)) { $where[] = ['a.goods_id', '=', $goods_id]; if (is_array($picture_type)) { $where[] = ['b.type', 'in', $picture_type]; } $list = Db::name('goods_picture') ->alias('a') ->join('goods_picture_type b', 'a.id=b.picture_id') ->field('DISTINCT a.id,a.url')->where($where)->order('id asc')->select()->toArray(); } else { $where[] = ['goods_id', '=', $goods_id]; $list = Db::name('goods_picture')->field('id,url')->where($where)->order('id asc')->select()->toArray(); } if ($list) { $result['list'] = $list; return $this->successResponse($result); } else { return $this->errorResponse(lang('no_data_found')); } } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } /** * 根据类型获取商品图片数量 * @return void */ public function getGoodsPictureCount() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } try { $goods_id = input('goods_id'); $goodsPictureCount['type0'] = Db::name('goods_picture')->where(['goods_id' => $goods_id])->count(); $goodsPictureCount['type1'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 1])->count(); $goodsPictureCount['type2'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 2])->count(); $goodsPictureCount['type3'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 3])->count(); $goodsPictureCount['type4'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 4])->count(); $goodsPictureCount['type5'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 5])->count(); $goodsPictureCount['type6'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 6])->count(); $goodsPictureCount['type7'] = Db::name('goods_picture_type')->where(['goods_id' => $goods_id, 'type' => 7])->count(); $result['goodsPictureCount'] = $goodsPictureCount; return $this->successResponse($result); } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } /** * 获取分销区域 */ private function getDisArea($id) { return Db::name('distribution_area') ->alias('da') ->join('deliver_region dr', 'dr.deliver_region_id=da.deliver_region_id') ->field("da.dis_currency,dr.region_name,da.dis_model") ->where('da.id', $id)->find(); } /** * 获取刊登信息 * @return array|int[] * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getPublishOrderInfo() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } $id = input('id'); $cancel_id = input('cancel_id'); if (!is_numeric($id)) { return $this->errorResponse(lang('invalid_id')); } try { $where = [ 'id' => $id, ]; $info = Db::name('publish_order')->field('*')->where($where)->find(); if ($info['three_cate_code']) { $info['cate_code'] = [$info['first_cate_code'], $info['second_cate_code'], $info['three_cate_code']]; } //////获取描述标题数据///////// $cancelInfo = Db::name('publish_order_cancel')->field('*')->where('id',$cancel_id)->find(); //////////////// $result['info'] = $info; $result['cancelInfo'] = $cancelInfo; return $this->successResponse($result); } catch (Exception $e) { return $this->errorResponse($e->getMessage()); } } /** * 保存刊登信息 * @return array */ public function savePublishOrder() { // 开始数据库事务 Db::startTrans(); try { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } $data = Request::post(); $id = $data['id']; // 验证ID的合法性 if (!is_numeric($id) || $id <= 0) { return $this->errorResponse(lang('invalid_id')); } // 数据验证 $validate = new \app\supplier\validate\PublishOrder(); $check_result = $validate->check($data); if (!$check_result) { return $this->errorResponse($validate->getError()); } ///////////////// $img_count = Db::name('publish_order_picture')->where('publish_order_id', $id)->count(); if ($img_count == 0) { return $this->errorResponse('请上传图片'); } $data['update_time'] = time(); $data['istemp'] = 1; $data['publish_status'] = 0;//未刊登 $data['audit_status'] = 2;//提交待审核 $where['id'] = $id; $update_result = Db::name('publish_order')->where($where)->withoutField('id,supplier_id,publish_order_code')->update($data); if ($update_result === FALSE) { // 回滚事务 Db::rollback(); return $this->errorResponse(lang('editing_failed')); } // 提交事务 Db::commit(); $result['url'] = url('/supplier/publishOrder/index')->build(); $result['message'] = lang('successfully_saved'); return $this->successResponse($result); } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 删除刊登信息 * @return array */ public function deletePublishOrder() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } $id = input('id'); if (!$id || !is_numeric($id)) { throw new Exception(lang('parameter_error')); } $condition['id'] = $id; $info = Db::name('publish_order')->field('id,publish_status,audit_status')->where($condition)->find(); if (!$info) { return $this->errorResponse(lang('delete_failed')); } else { if ($info['publish_status'] == 1) { return $this->errorResponse('刊登单已发布,不能删除'); } } // 启动事务 Db::startTrans(); try { $del_result = Db::name('publish_order')->where('id', $id)->delete(); if ($del_result) { ////执行成功,提交事务 Db::commit(); return $this->successResponse(lang('delete_successful')); } else { Db::rollback(); return $this->errorResponse(lang('delete_failed')); } } catch (\Exception $exc) { //// 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 上传商品图片 * @return array|int[] */ /** * 获取商品图片列表 * @return array|int[] */ public function getPublishOrderPictureList() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } try { $publish_order_id = input('publish_order_id'); $where[] = ['publish_order_id', '=', $publish_order_id]; $list = Db::name('publish_order_picture')->field('id,url')->where($where)->order('id asc')->select()->toArray(); if ($list) { $result['list'] = $list; return $this->successResponse($result); } else { return $this->errorResponse(lang('no_data_found')); } } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } /** * 删除商品图片 * @return array|int[] * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function deletePublishOrderPicture() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } $id = input('id'); if (!$id || !is_numeric($id)) { return $this->errorResponse(lang('parameter_error')); } $condition['id'] = $id; $info = Db::name('publish_order_picture')->field('id,publish_order_id,url')->where($condition)->find(); if (!$info) { return $this->errorResponse(lang('delete_failed')); } // 启动事务 Db::startTrans(); try { $del_result = Db::name('publish_order_picture')->where('id', $id)->delete(); if ($del_result) { ////执行成功,提交事务 Db::commit(); delpic($info['url']); return $this->successResponse(lang('delete_successful')); } else { Db::rollback(); return $this->errorResponse(lang('delete_failed')); } } catch (\Exception $exc) { //// 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } /** * 获取分类列表 * @return array */ public function getCategoryList() { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } try { $result['list'] = $this->getchildrenids(0); return $this->successResponse($result); } catch (\Exception $exc) { return $this->errorResponse($exc->getMessage()); } } /** * 循环获取分类数据 * @param $id * @return array|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ protected function getchildrenids($id) { $where['father_code'] = $id; $result = Db::name('category')->field('id,cate_code as value,cate_name as label')->where($where)->cacheAlways(TRUE, 0, 'category')->order('id asc')->select()->toArray(); if ($result) { foreach ($result as &$val) { $val['children'] = $this->getchildrenids($val['value']); //// } return $result; } } /** * 商品发布 * @return array|int[] */ public function goodsPublish() { // 开始数据库事务 Db::startTrans(); try { if (!Request::isPost()) { return $this->errorResponse(lang('request_method_incorrect')); } $publish_order_id = input('publish_order_id'); $goods_info = Db::name('goods')->field('id')->where('id', $publish_order_id)->find(); if ($goods_info) { $update_data = [ 'publish_status' => 1, 'update_time' => time(), ]; Db::name('goods')->where('id', $publish_order_id)->update($update_data); } else { return $this->errorResponse(lang('goods_not_exist')); } // 提交事务 Db::commit(); return $this->successResponse(lang('goods_publish_success')); } catch (Exception $exc) { // 回滚事务 Db::rollback(); return $this->errorResponse($exc->getMessage()); } } }