|
@@ -3,11 +3,14 @@
|
|
|
namespace app\api\service;
|
|
namespace app\api\service;
|
|
|
|
|
|
|
|
use app\adminapi\logic\external\ExternalConsultationLogic;
|
|
use app\adminapi\logic\external\ExternalConsultationLogic;
|
|
|
|
|
+use app\api\logic\ServiceOrderLogic;
|
|
|
use app\common\model\Config;
|
|
use app\common\model\Config;
|
|
|
use app\common\model\external\DouyinOrder;
|
|
use app\common\model\external\DouyinOrder;
|
|
|
|
|
+use app\common\model\external\DouyinRefundOrder;
|
|
|
use app\common\model\external\ExternalConsultation;
|
|
use app\common\model\external\ExternalConsultation;
|
|
|
use app\common\model\external\ExternalConsultationOrder;
|
|
use app\common\model\external\ExternalConsultationOrder;
|
|
|
use app\common\model\goods\Goods;
|
|
use app\common\model\goods\Goods;
|
|
|
|
|
+use app\common\model\recharge\RechargeOrder;
|
|
|
use app\common\model\user\User;
|
|
use app\common\model\user\User;
|
|
|
use app\common\model\user\UserAuth;
|
|
use app\common\model\user\UserAuth;
|
|
|
use app\common\model\works\ServiceWork;
|
|
use app\common\model\works\ServiceWork;
|
|
@@ -189,5 +192,179 @@ class DouYinService
|
|
|
throw new \Exception($e->getMessage());
|
|
throw new \Exception($e->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ public static function upReservation($params)
|
|
|
|
|
+ {
|
|
|
|
|
+ // $params['order_number']
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
|
|
|
|
|
+ if(!$order->isEmpty()){
|
|
|
|
|
+ // sn appointment_time
|
|
|
|
|
+ $result = ServiceOrderLogic::approvalChangeAppointment(['sn'=>RechargeOrder::where('work_id', $order->work_id)->value('sn'),'appointment_time'=>$params['appointment_time']]);
|
|
|
|
|
+ if (false === $result) {
|
|
|
|
|
+ throw new \Exception(ServiceOrderLogic::getError());
|
|
|
|
|
+ }
|
|
|
|
|
+ $order->fulfillment_status = ServiceWork::where('id', $order->work_id)->value('work_status');
|
|
|
|
|
+ $order->save();
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ return $order['id'];
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function getOrderDetail($params)
|
|
|
|
|
+ {
|
|
|
|
|
+ //抖音订单信息/商品信息/预约信息(地址、时间、履约状态与信息)
|
|
|
|
|
+ // $params['order_number'] user_id
|
|
|
|
|
+ $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
|
|
|
|
|
+ if($order->isEmpty()){
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ $orderInfo = $order->toArray();
|
|
|
|
|
+ empty($orderInfo['goods']) && $orderInfo['goods'] = [];
|
|
|
|
|
+ empty($orderInfo['serviceWork']) && $orderInfo['serviceWork'] = [];
|
|
|
|
|
+
|
|
|
|
|
+ $work_status = $orderInfo['serviceWork']['work_status']??0;
|
|
|
|
|
+ $performance = [];
|
|
|
|
|
+ // tmp
|
|
|
|
|
+ switch ($work_status){
|
|
|
|
|
+ case 0:
|
|
|
|
|
+ $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ case 3:
|
|
|
|
|
+ $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 4:
|
|
|
|
|
+ case 5:
|
|
|
|
|
+ case 6:
|
|
|
|
|
+ $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ $performance[] = ['status' => '服务中','title' => '服务中','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 7:
|
|
|
|
|
+ case 8:
|
|
|
|
|
+ $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ $performance[] = ['status' => '服务中','title' => '服务中','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ $performance[] = ['status' => '已完结','title' => '已完结','time' => date('Y-m-d H:i:s',time())];
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ $orderInfo['performance'] = $performance;
|
|
|
|
|
+
|
|
|
|
|
+ return $orderInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function refund($params)
|
|
|
|
|
+ {
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ // $params['order_number'] user_id
|
|
|
|
|
+ $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
|
|
|
|
|
+ if($order->isEmpty()){
|
|
|
|
|
+ throw new \Exception('订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ $orderInfo = $order->toArray();
|
|
|
|
|
+ $work_status = $orderInfo['serviceWork']['work_status']??0;
|
|
|
|
|
+ if(3 < $work_status){
|
|
|
|
|
+ throw new \Exception('该订单禁止退款');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DouyinRefundOrder::create([
|
|
|
|
|
+ 'refund_number' => generate_sn(DouyinRefundOrder::class, 'refund_number'),
|
|
|
|
|
+ 'order_number' => $orderInfo['order_number'],
|
|
|
|
|
+ 'transaction_id' => $orderInfo['transaction_id'],
|
|
|
|
|
+ 'reason' => $params['reason']??'',
|
|
|
|
|
+ 'refund_status' => 0,
|
|
|
|
|
+ 'user_id' => $orderInfo['user_id'],
|
|
|
|
|
+ 'refund_amount' => $orderInfo['paid_amount'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function refundExamine($params)
|
|
|
|
|
+ {
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ // $params['order_number'] user_id
|
|
|
|
|
+ $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
|
|
|
|
|
+ if($order->isEmpty()){
|
|
|
|
|
+ throw new \Exception('订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ $orderInfo = $order->toArray();
|
|
|
|
|
+ $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['refund_number'])->findOrEmpty();
|
|
|
|
|
+ if($params['is_examine_ok'] === 'pass'){
|
|
|
|
|
+ $douyinRefundOrder->refund_status = 2;
|
|
|
|
|
+ RechargeOrder::where('work_id', $orderInfo['work_id'])->update([
|
|
|
|
|
+ 'pay_status' => 2,
|
|
|
|
|
+ 'pay_time' => 0,
|
|
|
|
|
+ 'paid_amount' => 0,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ ServiceWork::where('id', $orderInfo['work_id'])->update([
|
|
|
|
|
+ 'work_status' => 0,
|
|
|
|
|
+ 'user_confirm_status' => 0,
|
|
|
|
|
+ 'service_status' => 4,
|
|
|
|
|
+ 'work_pay_status' => 0
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $douyinRefundOrder->refund_status = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ $douyinRefundOrder->save();
|
|
|
|
|
+
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+
|
|
|
|
|
+ // TODO 需接抖音支付接口
|
|
|
|
|
+ /*if($params['is_examine_ok'] === 'pass'){
|
|
|
|
|
+ //通过后向抖音申请退款
|
|
|
|
|
+ //https://open.douyin.com/api/trade_basic/v1/developer/refund_create/
|
|
|
|
|
+ }*/
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function refundNotify($params)
|
|
|
|
|
+ {
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['out_refund_no'])->findOrEmpty();
|
|
|
|
|
+ if($douyinRefundOrder->isEmpty()){
|
|
|
|
|
+ throw new \Exception('退款订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ if($douyinRefundOrder->refund_status == 0){
|
|
|
|
|
+ if($params['status'] === 'SUCCESS'){
|
|
|
|
|
+ $douyinRefundOrder->refund_status = 3;
|
|
|
|
|
+ DouyinOrder::where('order_number', $douyinRefundOrder->order_number)->update([
|
|
|
|
|
+ 'order_status' => 4,
|
|
|
|
|
+ 'pay_status' => 3,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }elseif($params['status'] === 'FAIL'){
|
|
|
|
|
+ $douyinRefundOrder->refund_status = 4;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ throw new \Exception('退款状态未知');
|
|
|
|
|
+ }
|
|
|
|
|
+ $douyinRefundOrder->save();
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ throw new \Exception($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|