12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zhengmingwei
- * Date: 2019/11/9
- * Time: 10:00 下午
- */
- namespace addons\unishop\controller;
- use addons\unishop\extend\Hashids;
- use addons\unishop\model\Area;
- use addons\unishop\model\Config;
- use addons\unishop\model\Evaluate;
- use addons\unishop\model\Product;
- use app\admin\model\unishop\Coupon as CouponModel;
- use addons\unishop\model\DeliveryRule as DeliveryRuleModel;
- use addons\unishop\model\OrderRefund;
- use app\admin\model\unishop\OrderRefundProduct;
- use think\Db;
- use think\Exception;
- use addons\unishop\model\Address as AddressModel;
- use think\Hook;
- use think\Loader;
- use addons\epay\library\Service;
- /**
- * 订单
- */
- class Order extends Base
- {
- /**
- * 允许频繁访问的接口
- * @var array
- */
- protected $frequently = ['getorders','getOrders','detail'];
- protected $noNeedLogin = ['count'];
- /**
- * @ApiTitle (创建订单)
- * @ApiSummary (创建订单)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="id", type=string, required=true, description="商品id")
- * @ApiReturn ({"code":1,"msg":"","data":{}})
- *
- * @ApiReturnParams (name="order_id", type="string", description="订单编号")
- * @ApiReturnParams (name="out_trade_no", type="string", description="商户订单号(支付用)")
- *
- * @ApiReturnParams (name="product.title", type="string", description="商品名称")
- * @ApiReturnParams (name="product.image", type="string", description="商品图片")
- * @ApiReturnParams (name="product.sales", type="integer", description="销量")
- * @ApiReturnParams (name="product.sales_price", type="string", description="销售价钱")
- * @ApiReturnParams (name="product.market_price", type="string", description="市场价钱")
- * @ApiReturnParams (name="product.id", type="string", description="商品id")
- * @ApiReturnParams (name="product.stock", type="integer", description="库存")
- * @ApiReturnParams (name="product.spec", type="integer", description="选中的规格")
- * @ApiReturnParams (name="product.number", type="integer", description="购买数量")
- *
- * @ApiReturnParams (name="address.id", type="integer", description="地址id")
- * @ApiReturnParams (name="address.name", type="string", description="收货人名称")
- * @ApiReturnParams (name="address.mobile", type="string", description="收货人电话")
- * @ApiReturnParams (name="address.address", type="string", description="收货人地址")
- * @ApiReturnParams (name="address.province_id", type="integer", description="省份id")
- * @ApiReturnParams (name="address.city_id", type="integer", description="城市id")
- * @ApiReturnParams (name="address.area_id", type="integer", description="地区id")
- * @ApiReturnParams (name="address.is_default", type="integer", description="是否默认")
- * @ApiReturnParams (name="address.province.name", type="integer", description="省份")
- * @ApiReturnParams (name="address.city.name", type="integer", description="城市")
- * @ApiReturnParams (name="address.area.name", type="integer", description="地区")
- *
- * @ApiReturnParams (name="coupon.id", type="integer", description="优惠券id")
- * @ApiReturnParams (name="coupon.title", type="string", description="优惠券名称")
- * @ApiReturnParams (name="coupon.least", type="integer", description="至少购买金额")
- * @ApiReturnParams (name="coupon.value", type="integer", description="满减金额")
- * @ApiReturnParams (name="coupon.starttime_text", type="integer", description="开始使用时间")
- * @ApiReturnParams (name="coupon.endtime_text", type="integer", description="到期使用时间")
- *
- * @ApiReturnParams (name="delivery.id", type="integer", description="货运id")
- * @ApiReturnParams (name="delivery.name", type="string", description="货运名称")
- * @ApiReturnParams (name="delivery.type", type="string", description="收费类型")
- * @ApiReturnParams (name="delivery.min", type="integer", description="至少购买量")
- * @ApiReturnParams (name="delivery.first", type="integer", description="首重数量")
- * @ApiReturnParams (name="delivery.first_fee", type="string", description="首重价钱")
- * @ApiReturnParams (name="delivery.additional", type="integer", description="需重数量")
- * @ApiReturnParams (name="delivery.additional_fee", type="string", description="需重价钱") *
- *
- */
- public function create()
- {
- $productId = input('id', 0);
- try {
- $user_id = $this->auth->id;
- // 单个商品
- if ($productId) {
- $number = input('number',1,'intval');
- $number = intval($number);
- $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
- $product = (new Product)->where(['id' => $productId, 'switch' => Product::SWITCH_ON, 'deletetime' => null])->find();
- /** 产品基础数据 **/
- $spec = input('spec', '');
- $productData[0] = $product->getDataOnCreateOrder($spec,$number);
- } else {
- // 多个商品
- $cart = input('cart');
- $carts = (new \addons\unishop\model\Cart)
- ->whereIn('id', $cart)
- ->with(['product'])
- ->order(['id' => 'desc'])
- ->select();
- foreach ($carts as $cart) {
- if ($cart->product instanceof Product) {
- $productData[] = $cart->product->getDataOnCreateOrder($cart->spec ? $cart->spec : '', $cart->number);
- }
- }
- }
- if (empty($productData) || !$productData) {
- $this->error(__('Product not exist'));
- }
- /** 默认地址 **/
- /*$address_map = ['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES];
- $address_id = input('address_id',0);
- if($address_id){
- $address_map = ['user_id' => $user_id, 'id' => $address_id];
- }
- $address = (new AddressModel)->where($address_map)->find();
- if ($address) {
- $area = (new Area)->whereIn('id', [$address->province_id, $address->city_id, $address->area_id])->column('name', 'id');
- $address = $address->toArray();
- $address['province']['name'] = $area[$address['province_id']];
- $address['city']['name'] = $area[$address['city_id']];
- $address['area']['name'] = $area[$address['area_id']];
- }
- */
- /** 可用优惠券 **/
- /*$coupon = CouponModel::all(function ($query) {
- $time = time();
- $query
- ->where(['switch' => CouponModel::SWITCH_ON])
- ->where('starttime', '<', $time)
- ->where('endtime', '>', $time);
- });
- if ($coupon) {
- $coupon = collection($coupon)->toArray();
- }*/
- /** 运费数据 **/
- /*$cityId = $address['city_id'] ? $address['city_id'] : 0;
- $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);*/
- $order_price = '0';
- $delivery_price = '0';
- foreach ($productData as &$product) {
- $product['image'] = Config::getImagesFullUrl($product['image']);
- $product['sales_price'] = round($product['sales_price'], 2);
- $product['market_price'] = round($product['market_price'], 2);
- $order_price = bcadd($order_price,$product['total_price'],2);
- }
- $this->success('', [
- 'product' => $productData,
- // 'address' => $address,
- // 'coupon' => $coupon,
- // 'delivery' => $delivery['list'],
- 'order_price' => $order_price,
- 'delivery_price' => $delivery_price,
- 'total_price' => bcadd($order_price,$delivery_price,2),
- 'wallet' => Db::name('user_wallet')->where('user_id',$this->auth->id)->find(),
- ]);
- } catch (Exception $e) {
- $this->error($e->getMessage(), false);
- }
- }
- /**
- * @ApiTitle (提交订单)
- * @ApiSummary (提交订单)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="coupon_id", type=string, required=true, description="优惠券id")
- * @ApiParams (name="product_id", type=string, required=true, description="商品id,多个用法(product_id,product_id,product_id)")
- * @ApiParams (name="number", type=string, required=true, description="商品数量,多个用法(number,number,number)")
- * @ApiParams (name="spec", type=string, required=true, description="规格,多个用法(spec|spec2,spec|spec2,spec|spec2)")
- * @ApiParams (name="city_id", type=integer, required=true, description="城市id")
- * @ApiParams (name="address_id", type=string, required=true, description="收货地址id")
- * @ApiParams (name="delivery_id", type=integer, required=true, description="运费模板id")
- * @ApiParams (name="remark", type=string, required=true, description="备注")
- * @ApiReturn ({"code":1,"msg":"","data":{}})
- *
- * @ApiReturnParams (name="order_id", type="string", description="订单编号")
- * @ApiReturnParams (name="out_trade_no", type="string", description="商户订单号(支付用)")
- *
- */
- public function submit()
- {
- $data = input();
- $pay_type = input('pay_type','wechat');
- if(!in_array($pay_type,['wechat','alipay','wallet'])){
- $this->error();
- }
- try {
- $validate = Loader::validate('\\addons\\unishop\\validate\\Order');
- if (!$validate->check($data, [], 'submit')) {
- throw new Exception($validate->getError());
- }
- Db::startTrans();
- // 判断创建订单的条件
- if (empty(Hook::get('create_order_before'))) {
- Hook::add('create_order_before', 'addons\\unishop\\behavior\\Order');
- }
- // 减少商品库存,增加"已下单未支付数量"
- if (empty(Hook::get('create_order_after'))) {
- Hook::add('create_order_after', 'addons\\unishop\\behavior\\Order');
- }
- $orderModel = new \addons\unishop\model\Order();
- $result = $orderModel->createOrder($this->auth->id, $data);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage(), false);
- }
- $this->success('', $result);
- }
- /**
- * @ApiTitle (获取运费模板)
- * @ApiSummary (获取运费模板)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="city_id", type=integer, required=true, description="城市id")
- * @ApiReturn ({"code":1,"msg":"","data":[]})
- *
- * @ApiReturnParams (name="id", type="integer", description="模板id")
- * @ApiReturnParams (name="name", type="string", description="模板名称")
- * @ApiReturnParams (name="type", type="string", description="模板类型")
- * @ApiReturnParams (name="min", type="integer", description="至少购买量")
- * @ApiReturnParams (name="first", type="integer", description="首重数量")
- * @ApiReturnParams (name="first_fee", type="string", description="首重价钱")
- * @ApiReturnParams (name="additional", type="integer", description="需重数量")
- * @ApiReturnParams (name="additional_fee", type="string", description="需重价钱") *
- *
- */
- public function getDelivery()
- {
- $cityId = input('city_id', 0);
- $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
- $this->success('', $delivery['list']);
- }
- /**
- * @ApiTitle (获取订单列表)
- * @ApiSummary (获取订单列表信息)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="type", type=integer, required=true, description="类型:0=全部,1=待付款,2=待发货,3=待收货,4=待评价,5=售后")
- * @ApiParams (name="page", type=integer, required=true, description="第几页")
- * @ApiParams (name="pagesize", type=integer, required=true, description="每页数量")
- * @ApiReturn ({"code":1,"msg":"","data":[]})
- *
- * @ApiReturnParams (name="out_trade_no", type="string", description="商户订单号")
- * @ApiReturnParams (name="order_price", type="string", description="订单原价钱")
- * @ApiReturnParams (name="discount_price", type="string", description="优惠多少钱")
- * @ApiReturnParams (name="delivery_price", type="string", description="运费多少钱")
- * @ApiReturnParams (name="total_price", type="string", description="订单实价")
- * @ApiReturnParams (name="pay_type", type="integer", description="支付类型")
- * @ApiReturnParams (name="id", type="string", description="下单ip")
- * @ApiReturnParams (name="remark", type="string", description="订单备注")
- * @ApiReturnParams (name="have_paid", type="integer", description="是否支付")
- * @ApiReturnParams (name="have_delivered", type="integer", description="是否发货")
- * @ApiReturnParams (name="have_received", type="integer", description="是否收货")
- * @ApiReturnParams (name="have_commented", type="integer", description="是否评论")
- * @ApiReturnParams (name="refund_status", type="integer", description="退款状态")
- * @ApiReturnParams (name="products[].id", type="string", description="商品id")
- * @ApiReturnParams (name="products[].title", type="string", description="商品名称")
- * @ApiReturnParams (name="products[].image", type="string", description="商品图片")
- * @ApiReturnParams (name="products[].number", type="integer", description="商品数量")
- * @ApiReturnParams (name="products[].price", type="string", description="商品价钱")
- * @ApiReturnParams (name="products[].spec", type="string", description="选中的规格")
- * @ApiReturnParams (name="products[].order_product_id", type="integer", description="订单商品id")
- * @ApiReturnParams (name="products[].evaluate", type="integer", description="是否已评价")
- * @ApiReturnParams (name="products[].refund", type="integer", description="是否已退款")
- * @ApiReturnParams (name="extend.express_number", type="integer", description="运单号")
- * @ApiReturnParams (name="order_id", type="string", description="订单id")
- * @ApiReturnParams (name="state", type="string", description="状态类型:0=全部,1=待付款,2=待发货,3=待收货,4=待评价,5=售后")
- * @ApiReturnParams (name="refund_status_text", type="string", description="已退款")
- */
- public function getOrders()
- {
- // 0=全部,1=待付款,3=待核销,4=已完成,40=待评价
- $type = input('type', 0);
- $page = input('page', 1);
- $pagesize = input('pagesize', 10);
- try {
- $orderModel = new \addons\unishop\model\Order();
- $result = $orderModel->getOrdersByType($this->auth->id, $type, $page, $pagesize);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('', $result);
- }
- //订单各个状态的数量
- public function getOrders_num(){
- // 0=全部,1=待付款,3=待核销,4=已完成,40=待评价
- $status = [
- [
- 'status' => 1,
- 'status_text' => '待付款',
- 'number' => 0,
- ],
- [
- 'status' => 3,
- 'status_text' => '待核销',
- 'number' => 0,
- ],
- [
- 'status' => 4,
- 'status_text' => '已完成',
- 'number' => 0,
- ],
- [
- 'status' => 40,
- 'status_text' => '待评价',
- 'number' => 0,
- ],
- ];
- $orderModel = new \addons\unishop\model\Order();
- foreach($status as $key => $val){
- $val['number'] = $orderModel->getOrdersByType_num($this->auth->id,$val['status']);
- $status[$key] = $val;
- }
- $this->success(1, $status);
- }
- /**
- * @ApiTitle (取消订单)
- * @ApiSummary (未支付的订单才叫取消,已支付的叫退货)
- * @ApiMethod (GET)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string", description="订单id")
- * @ApiReturn ({"code":1,"msg":"取消成功","data":true})
- *
- */
- public function cancel()
- {
- $order_id = input('order_id', 0);
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$order) {
- $this->error(__('Order not exist'));
- }
- switch ($order['status']) {
- case \addons\unishop\model\Order::STATUS_REFUND:
- $this->error('此订单已退款,无法取消');
- break;
- case \addons\unishop\model\Order::STATUS_CANCEL:
- $this->error('此订单已取消, 无需再取消');
- break;
- }
- if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) {
- $this->error('此订单已支付,无法取消');
- }
- if ($order['have_received'] != \addons\unishop\model\Order::RECEIVED_NO) {
- $this->error('此订单已核销,无法取消');
- }
- if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
- $order->status = \addons\unishop\model\Order::STATUS_CANCEL;
- $order->canceltime = time();
- $order->save();
- //归还优惠券
- /*$coupon_user_id = Db::name('unishop_order_extend')->where('order_id',$order_id)->value('coupon_user_id');
- if(!empty($coupon_user_id)){
- Db::name('unishop_coupon_user')->where('id',$coupon_user_id)->where('user_id',$this->auth->id)->update(['status'=>0]);
- }*/
- $this->success('取消成功', true);
- }
- }
- //已支付取消,申请退订
- public function payed_cancel()
- {
- $order_id = input('order_id', 0);
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$order) {
- $this->error(__('Order not exist'));
- }
- switch ($order['status']) {
- case \addons\unishop\model\Order::STATUS_REFUND:
- $this->error('此订单已退款,无法取消');
- break;
- case \addons\unishop\model\Order::STATUS_CANCEL:
- $this->error('此订单已取消, 无需再取消');
- break;
- }
- if ($order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
- $this->error('未支付订单,直接取消即可');
- }
- if ($order['have_received'] != \addons\unishop\model\Order::RECEIVED_NO) {
- $this->error('此订单已核销,无法退订');
- }
- Db::startTrans();
- if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_received'] == \addons\unishop\model\Order::RECEIVED_NO) {
- $refund_amount = $order['total_price'];
- $refund_status = 3; //申请售后状态 0=无,1=申请中,2=通过(让用户发货),3=通过,4=拒绝
- // 退款
- $params = [
- 'refund_status' => $refund_status,
- 'updatetime' => time(),
- 'refund_amount' => $refund_amount,
- 'status' => \addons\unishop\model\Order::STATUS_CANCEL,
- 'canceltime' => time(),
- ];
- if($refund_status == 3) {
- $params['had_refund'] = time();
- }
- $result = Db::name('unishop_order')->where(['id' => $order_id])->update($params);
- if (!$result) {
- Db::rollback();
- $this->error('取消失败');
- }
- //归还优惠券
- $coupon_user_id = Db::name('unishop_order_extend')->where('order_id',$order_id)->value('coupon_user_id');
- if(!empty($coupon_user_id)){
- Db::name('unishop_coupon_user')->where('id',$coupon_user_id)->where('user_id',$this->auth->id)->update(['status'=>0]);
- }
- //同意并执行退款
- if($refund_status == 3 && $refund_amount > 0){
- $order = Db::name('unishop_order')->where('id',$order_id)->find();
- if($order['pay_type'] == 2){
- $wallet = new \app\common\model\Wallet();
- $wallet_rs = $wallet->lockChangeAccountRemain($order['user_id'],'money',$refund_amount,32,'商城取消订单退款'.$order['out_trade_no'],'unishop_order',$order_id);
- if($wallet_rs['status'] === false){
- Db::rollback();
- $this->error($wallet_rs['msg']);
- }
- }elseif($order['pay_type'] == 3){
- $refund_result = $this->old_refund($order,$refund_amount);
- if($refund_result !== true){
- Db::rollback();
- $this->error($refund_result);
- }
- }
- }
- }
- Db::commit();
- $this->success('退订成功', true);
- }
- // 退款
- private function old_refund($order, $refund_price)
- {
- $table = 'unishop_order';
- $remark = '订单退款';
- if($order['pay_type'] == 3){
- $order['pay_type'] = 'wechat';
- }
- if($order['pay_type'] == 4){
- $order['pay_type'] = 'alipay';
- }
- // 生成退款单
- $refund_data = [
- 'order_id' => $order['id'],
- 'out_refund_no'=> createUniqueNo('R'),
- 'pay_fee' => $order['total_price'],
- 'refund_price' => $refund_price,
- 'pay_type' => $order['pay_type'],
- 'status' => 0,
- 'createtime' => time(),
- 'updatetime' => time(),
- 'table' => $table,
- 'table_id' => $order['id'],
- ];
- $refund_log_id = Db::name('pay_order_refund_log')->insertGetId($refund_data);
- if(!$refund_log_id){
- return '退款失败';
- }
- if ($order['pay_type'] == 'wechat' || $order['pay_type'] == 'alipay') {
- // 微信|支付宝退款
- // 退款数据
- $order_data = [
- 'out_trade_no' => $order['pay_out_trade_no']
- ];
- if ($order['pay_type'] == 'wechat') {
- $total_fee = $order['total_price'] * 100;
- $refund_fee = $refund_price * 100;
- $order_data = array_merge($order_data, [
- 'out_refund_no' => $refund_data['out_refund_no'],
- 'total_fee' => $total_fee,
- 'refund_fee' => $refund_fee,
- 'refund_desc' => $remark,
- ]);
- } else {
- $order_data = array_merge($order_data, [
- 'out_request_no' => $refund_data['out_refund_no'],
- 'refund_amount' => $refund_price,
- ]);
- }
- //
- if ($order['pay_type'] == 'wechat') {
- $wxpay = new \app\common\library\Wxpay;
- $result = $wxpay->WxPayRefund($order_data);
- // 微信通知回调 pay->notifyr
- if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
- Db::name('pay_order_refund_log')->where('id',$refund_log_id)->update(['status'=>1]);
- return true;
- } else {
- return $result['return_msg'];
- }
- } else {
- $result = Service::submitRefund($order['total_price'],$refund_price,$order['pay_out_trade_no'],$refund_data['out_refund_no'],$order['pay_type'],$remark,'');
- if($result['code'] == '10000'){
- Db::name('pay_order_refund_log')->where('id',$refund_log_id)->update(['status'=>1]);
- return true;
- }else{
- return $result['msg'];
- }
- /* return 'alipay wrong way';
- $alipay = new \app\common\library\AliPay;
- $result = $alipay->AliPayRefund($order_data);
- // 支付宝通知回调 pay->notifyx
- return $result;*/
- /*if ($result['code'] == "10000") {
- return true;
- } else {
- throw new \Exception($result['msg']);
- }*/
- }
- // { // 微信返回结果
- // "return_code":"SUCCESS",
- // "return_msg":"OK",
- // "appid":"wx39cd0799d4567dd0",
- // "mch_id":"1481069012",
- // "nonce_str":"huW9eIAb5BDPn0Ma",
- // "sign":"250316740B263FE53F5DFF50AF5A8FA1",
- // "result_code":"SUCCESS",
- // "transaction_id":"4200000497202004072822298902",
- // "out_trade_no":"202010300857029180027000",
- // "out_refund_no":"1586241595",
- // "refund_id":"50300603862020040700031444448",
- // "refund_channel":[],
- // "refund_fee":"1",
- // "coupon_refund_fee":"0",
- // "total_fee":"1",
- // "cash_fee":"1",
- // "coupon_refund_count":"0",
- // "cash_refund_fee":"1
- // }
- // { // 支付宝返回结果
- // "code": "10000",
- // "msg": "Success",
- // "buyer_logon_id": "157***@163.com",
- // "buyer_user_id": "2088902485164146",
- // "fund_change": "Y",
- // "gmt_refund_pay": "2020-08-15 16:11:45",
- // "out_trade_no": "202002460317545607015300",
- // "refund_fee": "0.01",
- // "send_back_fee": "0.00",
- // "trade_no": "2020081522001464141438570535"
- // }
- }
- return true;
- }
- /**
- * @ApiTitle (删除订单)
- * @ApiSummary (只能删除已取消或已退货的订单)
- * @ApiMethod (GET)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string", description="订单id")
- * @ApiReturn ({"code":1,"msg":"删除成功","data":true})
- *
- */
- public function delete()
- {
- $order_id = input('order_id', 0);
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$order) {
- $this->error(__('Order not exist'));
- }
- if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL) {
- $this->error('只能删除已取消或已退货的订单');
- }
- if ($order['status'] == \addons\unishop\model\Order::STATUS_REFUND && $order['refund_status'] == \addons\unishop\model\Order::REFUND_STATUS_APPLY) {
- $this->error('订单退款中,不可删除订单');
- }
- $order->delete();
- $this->success('删除成功', true);
- }
- /**
- * @ApiTitle (确认收货)
- * @ApiSummary (确认收货)
- * @ApiMethod (GET)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string", description="订单id")
- * @ApiReturn ({"code":1,"msg":"已确认收货","data":true})
- *
- */
- public function received()
- {
- $order_id = input('order_id', 0);
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$order) {
- $this->error(__('Order not exist'));
- }
- if ($order->have_delivered == 0) {
- $this->error('未发货,不能确认收货');
- }
- $order->have_received = time();
- $order->save();
- $this->success('已确认收货', true);
- }
- /**
- * @ApiTitle (发表评论/评价)
- * @ApiSummary (发表评论/评价)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string", description="订单id")
- * @ApiParams (name="rate", type="integer", description="分数/星星")
- * @ApiParams (name="anonymous", type="integer", description="是否匿名")
- * @ApiParams (name="comment", type="string", description="评价内容")
- * @ApiParams (name="product_id", type="string", description="商品id")
- * @ApiReturn ({"code":1,"msg":"感谢评价","data":true})
- *
- */
- public function comment()
- {
- $rate = input('rate', 5);
- $anonymous = input('anonymous', 0);
- $images = input('images','','trim');
- $comment = input('comment');
- $order_id = input('order_id', 0);
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- $product_id = input('product_id');
- $product_id = \addons\unishop\extend\Hashids::decodeHex($product_id);
- $orderProductModel = new \addons\unishop\model\OrderProduct();
- $orderProduct = $orderProductModel->field('id,id as order_product_id,spec')->where(['product_id' => $product_id, 'order_id' => $order_id, 'user_id' => $this->auth->id])->find();
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$orderProduct || !$order) {
- $this->error(__('Order not exist'));
- }
- if ($order->have_received == $orderModel::RECEIVED_NO) {
- $this->error(__('未核销,不可评价'));
- }
- $images_arr = explode(',',$images);
- if(count($images_arr) > 5){
- $this->error('最多上传5张图片');
- }
- $result = false;
- try {
- $evaluate = new Evaluate();
- $evaluate->user_id = $this->auth->id;
- $evaluate->order_id = $order_id;
- $evaluate->order_product_id = $orderProduct->order_product_id;
- $evaluate->product_id = $product_id;
- $evaluate->rate = $rate;
- $evaluate->anonymous = $anonymous;
- $evaluate->images = $images;
- $evaluate->comment = $comment;
- $evaluate->spec = $orderProduct->spec;
- $result = $evaluate->save();
- $orderProduct = Db::name('unishop_order_product')->where(['order_id' => $order_id])->count();
- $orderevaluate = Db::name('unishop_evaluate')->where(['order_id' => $order_id])->count();
- if ($result && ($orderProduct == $orderevaluate)) {
- $order->have_commented = time();
- $order->save();
- }
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success(__('Thanks for the evaluation'));
- } else {
- $this->error(__('Evaluation failure'));
- }
- }
- /**
- * @ApiTitle (获取订单数量)
- * @ApiSummary (获取订单数量)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiReturn ({"code":1,"msg":"","data":{}})
- *
- * @ApiReturnParams (name="unpaid", type="integer", description="未支付数量")
- * @ApiReturnParams (name="undelivered", type="integer", description="未发货数量")
- * @ApiReturnParams (name="unreceived", type="integer", description="未收货数量")
- * @ApiReturnParams (name="uncomment", type="integer", description="未评价数量")
- * @ApiReturnParams (name="refund", type="integer", description="正在售后的数量")
- *
- */
- public function count()
- {
- if (!$this->auth->isLogin()) {
- $this->error('');
- }
- $order = new \addons\unishop\model\Order();
- $list = $order
- ->where([
- 'user_id' => $this->auth->id,
- ])
- ->where('status', '<>', \addons\unishop\model\Order::STATUS_CANCEL)
- ->where(function ($query) {
- $query
- ->whereOr([
- 'have_paid' => \addons\unishop\model\Order::PAID_NO,
- 'have_delivered' => \addons\unishop\model\Order::DELIVERED_NO,
- 'have_received' => \addons\unishop\model\Order::RECEIVED_NO,
- 'have_commented' => \addons\unishop\model\Order::COMMENTED_NO
- ])
- ->whereOr('refund_status', '>', \addons\unishop\model\Order::REFUND_STATUS_NONE);
- })
- ->field('have_paid,have_delivered,have_received,have_commented,refund_status,had_refund')
- ->select();
- $data = [
- 'unpaid' => 0,
- 'undelivered' => 0,
- 'unreceived' => 0,
- 'uncomment' => 0,
- 'refund' => 0
- ];
- foreach ($list as $item) {
- switch (true) {
- case $item['have_paid'] > 0 && $item['have_delivered'] > 0 && $item['have_received'] > 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
- $data['uncomment']++;
- break;
- case $item['have_paid'] > 0 && $item['have_delivered'] > 0 && $item['have_received'] == 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
- $data['unreceived']++;
- break;
- case $item['have_paid'] > 0 && $item['have_delivered'] == 0 && $item['have_received'] == 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
- $data['undelivered']++;
- break;
- case $item['have_paid'] == 0 && $item['have_delivered'] == 0 && $item['have_received'] == 0 && $item['have_commented'] == 0 && $item['refund_status'] == 0:
- $data['unpaid']++;
- break;
- case $item['refund_status'] > 0 && $item['had_refund'] == 0 && $item['refund_status'] != 3:
- $data['refund']++;
- break;
- }
- }
- $this->success('', $data);
- }
- /**
- * @ApiTitle (订单详情细节)
- * @ApiSummary (订单详情细节)
- * @ApiMethod (GET)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string",required=true, description="订单id")
- * @ApiReturn ({"code":1,"msg":"","data":{}})
- *
- * @ApiReturnParams (name="out_trade_no", type="string", description="商户订单号")
- * @ApiReturnParams (name="order_price", type="string", description="订单原价钱")
- * @ApiReturnParams (name="discount_price", type="string", description="优惠多少钱")
- * @ApiReturnParams (name="delivery_price", type="string", description="运费多少钱")
- * @ApiReturnParams (name="total_price", type="string", description="订单实价")
- * @ApiReturnParams (name="pay_type", type="integer", description="支付类型")
- * @ApiReturnParams (name="id", type="string", description="下单ip")
- * @ApiReturnParams (name="remark", type="string", description="订单备注")
- * @ApiReturnParams (name="have_paid", type="integer", description="是否支付")
- * @ApiReturnParams (name="have_delivered", type="integer", description="是否发货")
- * @ApiReturnParams (name="have_received", type="integer", description="是否收货")
- * @ApiReturnParams (name="have_commented", type="integer", description="是否评论")
- * @ApiReturnParams (name="refund_status", type="integer", description="退款状态")
- * @ApiReturnParams (name="products[].id", type="string", description="商品id")
- * @ApiReturnParams (name="products[].title", type="string", description="商品名称")
- * @ApiReturnParams (name="products[].image", type="string", description="商品图片")
- * @ApiReturnParams (name="products[].number", type="integer", description="商品数量")
- * @ApiReturnParams (name="products[].price", type="string", description="商品价钱")
- * @ApiReturnParams (name="products[].spec", type="string", description="选中的规格")
- * @ApiReturnParams (name="products[].order_product_id", type="integer", description="订单商品id")
- * @ApiReturnParams (name="products[].evaluate", type="integer", description="是否已评价")
- * @ApiReturnParams (name="products[].refund", type="integer", description="是否已退款")
- * @ApiReturnParams (name="express_number", type="integer", description="运单号")
- * @ApiReturnParams (name="pay_type_text", type="string", description="支付类型简述")
- * @ApiReturnParams (name="refund_status_text", type="string", description="退款状态简述")
- * @ApiReturnParams (name="delivery.username", type="string", description="收货人名称")
- * @ApiReturnParams (name="delivery.mobile", type="string", description="收货人电话")
- * @ApiReturnParams (name="delivery.address", type="string", description="收货人地址")
- *
- */
- public function detail()
- {
- $order_id = input('order_id', 0);
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- try {
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel
- ->with([
- 'products' => function ($query) {
- $query->field('id,id as order_product_id,title,image,number,price,spec,order_id,product_id');
- },
- 'evaluate' => function ($query) {
- $query->field('id,order_id,order_product_id,product_id');
- }
- ])
- ->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if ($order) {
- $order = $order->append(['state', 'paidtime', 'deliveredtime', 'receivedtime', 'commentedtime', 'pay_type_text', 'refund_status_text'])->toArray();
- $order['state_text'] = $orderModel->getStatetextAttr($order['state'],$order['refund_status']);//状态中文
- // 是否已评论
- $evaluate = array_column($order['evaluate'], 'order_product_id');
- foreach ($order['products'] as &$product) {
- $product['image'] = Config::getImagesFullUrl($product['image']);
- if (in_array($product['order_product_id'], $evaluate)) {
- $product['evaluate'] = true;
- } else {
- $product['evaluate'] = false;
- }
- }
- unset($order['evaluate']);
- unset($order['extend']);
- unset($order['pay_out_trade_no']);
- //电子凭证,核销码
- $qrcode_string = 'order_hexiao_no|' . $order['out_trade_no'];
- $order['order_hexiao_qrcode'] = httpurllocal($this->inviteimage($qrcode_string));
- }
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('', $order);
- }
- //生成核销码
- private function inviteimage($introcode) {
- $params['text'] = $introcode;
- $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
- $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
- if (!is_dir($qrcodePath)) {
- @mkdir($qrcodePath);
- }
- if (is_really_writable($qrcodePath)) {
- $filename = md5(implode('', $params)) . '.png';
- $filePath = $qrcodePath . $filename;
- $qrcode_service->writeFile($filePath);
- }
- return '/uploads/qrcode/' . $filename;
- }
- /**
- * @ApiTitle (申请售后信息)
- * @ApiSummary (申请售后信息)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string",required=true, description="订单id")
- * @ApiReturn ({"code":1,"msg":"","data":{}})
- *
- * @ApiReturnParams (name="status", type="string", description="订单状态:-1=退货,0=取消订单,1=正常啊")
- * @ApiReturnParams (name="total_price", type="string", description="订单总价钱")
- * @ApiReturnParams (name="delivery_price", type="string", description="订单运费")
- * @ApiReturnParams (name="have_paid", type="integer", description="是否支付")
- * @ApiReturnParams (name="have_delivered", type="integer", description="是否发货")
- * @ApiReturnParams (name="have_received", type="integer", description="是否收货")
- * @ApiReturnParams (name="have_commented", type="integer", description="是否评论")
- * @ApiReturnParams (name="refund_status", type="integer", description="退款状态")
- * @ApiReturnParams (name="products[].id", type="string", description="商品id")
- * @ApiReturnParams (name="products[].title", type="string", description="商品名称")
- * @ApiReturnParams (name="products[].image", type="string", description="商品图片")
- * @ApiReturnParams (name="products[].number", type="integer", description="商品数量")
- * @ApiReturnParams (name="products[].price", type="string", description="商品价钱")
- * @ApiReturnParams (name="products[].spec", type="string", description="选中的规格")
- * @ApiReturnParams (name="products[].order_product_id", type="integer", description="订单商品id")
- * @ApiReturnParams (name="products[].choose", type="integer", description="是否选中")
- * @ApiReturnParams (name="refund_status_text", type="string", description="退款状态简述")
- * @ApiReturnParams (name="refund.id", type="string", description="退款信息id")
- * @ApiReturnParams (name="refund.amount", type="float",required=true, description="退款金额")
- * @ApiReturnParams (name="refund.service_type", type="string",required=true, description="服务类型:0=我要退款无需退货,1=我要退货退款,2=换货")
- * @ApiReturnParams (name="refund.receiving_status", type="integer",required=true, description="货物状态:0=未收到,1=已收到")
- * @ApiReturnParams (name="refund.reason_type", type="string",required=true, description="换货原因")
- * @ApiReturnParams (name="refund.refund_explain", type="string",required=true, description="退款说明")
- * @ApiReturnParams (name="refund.express_number", type="string",required=true, description="寄货物流单号")
- *
- */
- public function refundInfo()
- {
- $order_id = input('order_id');
- $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel
- ->with([
- 'products' => function ($query) {
- $query->field('id,order_id,image,number,price,spec,title,product_id,(1) as choose');
- },
- 'refund',
- 'refundProducts'
- ])
- ->field('id,status,total_price,delivery_price,have_commented,have_delivered,have_paid,have_received,refund_status')
- ->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$order) {
- $this->error(__('Order not exist'));
- }
- $order = $order->append(['refund_status_text'])->toArray();
- foreach ($order['products'] as &$product) {
- $product['image'] = Config::getImagesFullUrl($product['image']);
- $product['choose'] = 0;
- // 如果是已提交退货的全选
- if ($order['status'] == \addons\unishop\model\Order::STATUS_REFUND) {
- foreach ($order['refund_products'] as $refundProduct) {
- if ($product['order_product_id'] == $refundProduct['order_product_id']) {
- $product['choose'] = 1;
- }
- }
- }
- }
- unset($order['refund_products']);
- $this->success('', $order);
- }
- /**
- * @ApiTitle (提交申请售后)
- * @ApiSummary (提交申请售后)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string",required=true, description="订单id")
- * @ApiParams (name="amount", type="float",required=true, description="退款金额")
- * @ApiParams (name="service_type", type="string",required=true, description="服务类型:0=我要退款无需退货,1=我要退货退款,2=换货")
- * @ApiParams (name="receiving_status", type="integer",required=true, description="货物状态:0=未收到,1=已收到")
- * @ApiParams (name="reason_type", type="string",required=true, description="换货原因")
- * @ApiParams (name="refund_explain", type="string",required=true, description="退款说明")
- * @ApiParams (name="order_product_id", type="integer",required=true, description="订单的商品的id")
- * @ApiReturn ({"code":1,"msg":"提交","data":1})
- *
- */
- public function refund()
- {
- $order_id = input('order_id');
- $order_id = Hashids::decodeHex($order_id);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
- if (!$order) {
- $this->error(__('Order not exist'));
- }
- /*if ($order['have_paid'] == 0) {
- $this->error(__('订单未支付,可直接取消,无需申请售后'));
- }*/
- if ($order['have_delivered'] == 0) {
- $this->error(__('订单未发货,可直接取消,无需申请售后'));//发货的才能走售后,未发货的走取消
- }
- if($order->status == 0){
- $this->error('当前订单不能申请退款');
- }
- if($order->status == -1){
- $this->error('当前订单已经申请过退款');
- }
- //$amount = input('amount', 0);
- $amount = $order->total_price;
- $serviceType = input('service_type',1);
- $receivingStatus = input('receiving_status',1);
- $reasonType = input('reason_type','');
- $refundExplain = input('refund_explain','');
- $images = input('images','');
- // $orderProductId = input('order_product_id');
- $orderProductId = Db::name('unishop_order_product')->where('order_id',$order_id)->column('product_id');
- $orderProductId = implode(',', $orderProductId);
- if (!$orderProductId) {
- $this->error(__('Please select goods'));
- }
- if (!in_array($receivingStatus, [OrderRefund::UNRECEIVED, OrderRefund::RECEIVED])) {
- $this->error(__('Please select goods status'));
- }
- if (!in_array($serviceType, [OrderRefund::TYPE_REFUND_NORETURN, OrderRefund::TYPE_REFUND_RETURN, OrderRefund::TYPE_EXCHANGE])) {
- $this->error(__('Please select service type'));
- }
- if (in_array($serviceType, [OrderRefund::TYPE_REFUND_NORETURN, OrderRefund::TYPE_REFUND_RETURN]) && $order['total_price'] > 0) {
- if (!$amount) {
- $this->error(__('Please fill in the refund amount'));
- }
- }
- try {
- Db::startTrans();
- $orderRefund = new OrderRefund();
- $orderRefund->user_id = $this->auth->id;
- $orderRefund->order_id = $order_id;
- $orderRefund->receiving_status = $receivingStatus;
- $orderRefund->service_type = $serviceType;
- $orderRefund->reason_type = $reasonType;
- $orderRefund->amount = $amount;
- $orderRefund->refund_explain = $refundExplain;
- $orderRefund->images = $images;
- $orderRefund->save();
- $productIdArr = explode(',', $orderProductId);
- $refundProduct = [];
- foreach ($productIdArr as $orderProductId) {
- $tmp['order_product_id'] = $orderProductId;
- $tmp['order_id'] = $order_id;
- $tmp['user_id'] = $this->auth->id;
- $tmp['refund_id'] = $orderRefund['id'];
- $tmp['createtime'] = time();
- $refundProduct[] = $tmp;
- }
- (new OrderRefundProduct)->insertAll($refundProduct);
- $order->status = \addons\unishop\model\Order::STATUS_REFUND;
- $order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_APPLY;
- $order->save();
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('已申请', 1);
- }
- /**
- * @ApiTitle (售后发货)
- * @ApiSummary (售后发货)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="order_id", type="string",required=true, description="订单id")
- * @ApiParams (name="express_number", type="string",required=true, description="寄货物流单号")
- * @ApiReturn ({"code":1,"msg":"","data":1})
- *
- */
- public function refundDelivery()
- {
- $orderId = input('order_id');
- $expressNumber = input('express_number');
- if (!$expressNumber) {
- $this->error(__('Please fill in the express number'));
- }
- $orderId = Hashids::decodeHex($orderId);
- $orderModel = new \addons\unishop\model\Order();
- $order = $orderModel
- ->where(['id' => $orderId, 'user_id' => $this->auth->id])
- ->with(['refund'])->find();
- if (!$order || !$order->refund) {
- $this->error(__('Order not exist'));
- }
- try {
- Db::startTrans();
- $order->refund->express_number = $expressNumber;
- $order->refund_status = \addons\unishop\model\Order::REFUND_STATUS_APPLY;
- if ($order->refund->save() && $order->save()) {
- Db::commit();
- } else {
- throw new Exception(__('Operation failed'));
- }
- } catch (Exception $e) {
- Db::rollback();
- $this->success($e->getMessage());
- }
- $this->success('', 1);
- }
- /**
- * @ApiTitle (快递查询)
- * @ApiSummary (快递查询)
- * @ApiMethod (POST)
- * @ApiHeaders (name=cookie, type=string, required=false, description="用户会话的cookie")
- * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
- * @ApiParams (name="express", type="string",required=true, description="寄货物流公司")
- * @ApiParams (name="expresssn", type="string",required=true, description="寄货物流单号")
- * @ApiReturn ({"code":1,"msg":"","data":1})
- *
- */
- public function express() {
- $params = input();
- if (!class_exists(\addons\expressquery\library\Expressquery::class)) {
- $this->error('请先安装插件《物流信息接口》', []);
- }
- $info = get_addon_info('expressquery');
- if ($info['state'] == 0) {
- $this->error('请开启插件《物流信息接口》', []);
- }
- $expModle = new \addons\expressquery\library\Expressquery();
- $list = $expModle->getExpressList($params['express'], $params['expresssn']);
- if ($list['code'] == 0) {
- $this->error($list['msg']);
- }
- $expressInfo = Db::name('expressquery')->where(['express' => $params['express']])->find();
- $this->success('', [
- 'message' => $list['data'] ?? [],
- 'company' => $expressInfo['name'] ?? '快递单号'
- ]);
- }
- }
|