From a39115a3043e6074e1087fedb81ab363026e6b36 Mon Sep 17 00:00:00 2001
From: lanzu_qsy <334039090@qq.com>
Date: Tue, 8 Sep 2020 09:32:27 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=86=E8=B4=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Common/Rpc.php | 32 +++++++++
.../ImsCjdcOrderMainController.php | 4 +-
app/Admin/Extensions/CheckRow.php | 8 ++-
app/Admin/Extensions/OrderPrint.php | 56 ++++++++++++----
app/Admin/Extensions/OrderStateHandle.php | 33 ++++-----
app/Admin/Forms/SelectHorseman.php | 6 +-
app/Http/Controllers/TestController.php | 13 +++-
app/Libs/feier_print/api_php_demo.php | 34 +++++++---
app/Models/ImsCjdcOrderMain.php | 2 +
composer.json | 1 +
composer.lock | 67 ++++++++++++++++++-
11 files changed, 203 insertions(+), 53 deletions(-)
create mode 100644 app/Admin/Common/Rpc.php
diff --git a/app/Admin/Common/Rpc.php b/app/Admin/Common/Rpc.php
new file mode 100644
index 0000000..82b815f
--- /dev/null
+++ b/app/Admin/Common/Rpc.php
@@ -0,0 +1,32 @@
+request(
+ uniqid(),
+ self::SEPARATE_ACCOUNTS,
+ ['orderMainId' => $oid,'userId'=>$uid]);
+ $response = $client->send($request);
+ return $response->getBody()->getContents();
+ }
+
+
+}
diff --git a/app/Admin/Controllers/ImsCjdcOrderMainController.php b/app/Admin/Controllers/ImsCjdcOrderMainController.php
index 08c55a7..4f4a340 100644
--- a/app/Admin/Controllers/ImsCjdcOrderMainController.php
+++ b/app/Admin/Controllers/ImsCjdcOrderMainController.php
@@ -50,14 +50,16 @@ class ImsCjdcOrderMainController extends AdminController
});
$grid->actions(function (Grid\Displayers\Actions $actions) use ($grid){
+
$state = $actions->row->state;
if ($state==2){
$actions->append(new OrderStateHandle('接单',3));
}elseif ($state==311){
$actions->append(new OrderStateHandle('完成',4));
+ $actions->append(new OrderPrint('打印'));
}elseif ($state==3){
$actions->append(new OrderPrint('打印'));
- $actions->append(new CheckRow($actions->row->id,'自送'));
+ $actions->append(new CheckRow($actions->row->id,$grid->model()->getCurrentPage(),'自送'));
}
$actions->append(new OrderDetail('详情'));
});
diff --git a/app/Admin/Extensions/CheckRow.php b/app/Admin/Extensions/CheckRow.php
index 7998b5d..5d5ca48 100644
--- a/app/Admin/Extensions/CheckRow.php
+++ b/app/Admin/Extensions/CheckRow.php
@@ -14,21 +14,25 @@ class CheckRow extends RowAction
protected $title;
protected $order_id;
- public function __construct($orderId,$title=null)
+ protected $currentPage;
+ public function __construct($orderId,$currentPage,$title=null)
{
$this->order_id = $orderId;
+ $this->currentPage = $currentPage;
parent::__construct($title);
}
public function render()
{
+
// 实例化表单类并传递自定义参数
- $form = SelectHorseman::make(['order_id'=>$this->order_id]);
+ $form = SelectHorseman::make(['order_id'=>$this->order_id,'current_page'=>$this->currentPage]);
return Modal::make()
->lg()
->title($this->title)
->body($form)
->button($this->title);
+
}
}
diff --git a/app/Admin/Extensions/OrderPrint.php b/app/Admin/Extensions/OrderPrint.php
index 0ecd573..c37c576 100644
--- a/app/Admin/Extensions/OrderPrint.php
+++ b/app/Admin/Extensions/OrderPrint.php
@@ -7,12 +7,14 @@ namespace App\Admin\Extensions;
use App\Models\Feprint;
use App\Models\ImsCjdcOrderMain;
use Dcat\Admin\Grid\RowAction;
+use Graze\GuzzleHttp\JsonRpc\Client;
use Illuminate\Http\Request;
class OrderPrint extends RowAction
{
protected $title;
- public function __construct($title=null)
+
+ public function __construct($title = null)
{
parent::__construct($title);
@@ -20,9 +22,14 @@ class OrderPrint extends RowAction
public function handle(Request $request)
{
- $id = $this->getKey();
- $this->doPrint();
- dd($id);
+ $oid = $this->getKey();
+ $result = $this->doPrint($oid);
+ if ($result){
+ return $this->response()->success('操作成功');
+ }else{
+ return $this->response()->success('打印失败');
+ }
+
}
/**
@@ -35,34 +42,55 @@ class OrderPrint extends RowAction
}
- public function doPrint()
+ public function doPrint($oid)
{
- $oid = $this->getKey();
+
$row = ImsCjdcOrderMain::find($oid);
//>>1.获取打印机状态
$result = $this->getPrintStatus($row->market_id);
+
//>>2.调用打印
- if ($result==1){
- $this->feiErPrint($row->order_num);
+ if ($result == 1) {
+ $res = $this->rpcPrint($oid);
+ $res = json_decode($res, true)['result'];
+ $res = json_decode($res);
+
+ //>>3.记录打印次数
+ if ($res->msg == 'ok' && $res->ret == 0) {
+ //记录打印次数
+ $row->print_num +=1;
+ return $row->save();
+ } else {
+ return false;
+ }
}
- //>>3.记录打印次数
+
}
/**
- * @param $oid //主订单ID
+ * @param $oid //主订单ID
* @return int
*/
public function getPrintStatus($mid)
{
- $fe = Feprint::where('market_id',$mid)->first();
- if ($fe){
- return $fe->status;
- }else{
+ $fe = Feprint::where('market_id', $mid)->first();
+ if ($fe) {
+ return $fe->status;
+ } else {
return -1;
}
}
+
+ public function rpcPrint($oid)
+ {
+ $client = Client::factory(env('RPC_SITE_HOST'));
+ $request = $client->request(uniqid(), '/feie/doPrint', ['oid' => $oid]);
+ $response = $client->send($request);
+ return $response->getBody()->getContents();
+ }
+
public function feiErPrint($order_num)
{
include_once app_path('Libs\feier_print\api_php_demo.php');
diff --git a/app/Admin/Extensions/OrderStateHandle.php b/app/Admin/Extensions/OrderStateHandle.php
index c653c23..e7b98a4 100644
--- a/app/Admin/Extensions/OrderStateHandle.php
+++ b/app/Admin/Extensions/OrderStateHandle.php
@@ -1,11 +1,13 @@
state = $state;
-
}
-
-
/**
* 处理请求
*
@@ -37,19 +35,18 @@ class OrderStateHandle extends RowAction
$id = $this->getKey();
$orderMain = new ImsCjdcOrderMain();
$state = $request->get('state');
- if ($state==30){
- $content = new Content();
- $content = $this->showForm($content);
- return $content;
-
- dd('弹出表单');
- //$res = $orderMain->updateShippingType($id,1);
- }elseif ($state==100){
-
- }else{
- $res = $orderMain->modifyState($id,$state);
+ $res = $orderMain->modifyState($id,$state);
+ if ($res&&$state==4){
+ $order = $orderMain::where('id',$id)->first();
+ //记录分账流水
+ $result = json_decode(Rpc::separateAccounts($id,$order->user_id));
+ if ($result->result){
+ return $this->response()->success('操作成功')->refresh();
+ }else{
+ Log::error('订单完成时分账接口调用失败',$result);
+ return $this->response()->error('操作失败')->refresh();
+ }
}
-
if ($res==true){
return $this->response()->success('操作成功')->refresh();
}else{
@@ -69,8 +66,4 @@ class OrderStateHandle extends RowAction
];
}
- public function showForm(Content $content)
- {
- return $content->title('站内自送')->body("
hello world!
");
- }
}
diff --git a/app/Admin/Forms/SelectHorseman.php b/app/Admin/Forms/SelectHorseman.php
index 53a1812..dd2d1a4 100644
--- a/app/Admin/Forms/SelectHorseman.php
+++ b/app/Admin/Forms/SelectHorseman.php
@@ -22,9 +22,10 @@ class SelectHorseman extends Form
{
$hid = request()->get('horseman_id');
$oid = request()->get('order_id');
- $result = ImsCjdcOrderMain::where('id',$oid)->update(['shipping_type'=>1,'horseman_id'=>$hid]);
+ $current_page = request()->get('current_page');
+ $result = ImsCjdcOrderMain::where('id',$oid)->update(['shipping_type'=>1,'horseman_id'=>$hid,'updated_at'=>time()]);
if ($result){
- return $this->success('操作成功', '/order');
+ return $this->success('操作成功',"order?page={$current_page}");
}else{
return $this->error('操作失败');
}
@@ -40,6 +41,7 @@ class SelectHorseman extends Form
->options(LanzuServiceHorseman::getHorseman())
->required();
$this->hidden('order_id')->value($this->data['order_id']);
+ $this->hidden('current_page')->value($this->data['current_page']);
}
/**
diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php
index 7f03923..00708e4 100644
--- a/app/Http/Controllers/TestController.php
+++ b/app/Http/Controllers/TestController.php
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
+use Graze\GuzzleHttp\JsonRpc\Client;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -9,10 +10,18 @@ use App\Http\Controllers\Controller as BaseController;
use Illuminate\Support\Facades\Storage;
use App\Models\FinancialRecord;
+
+
class TestController extends BaseController
{
public function Test(){
-
- dd(22);
+ $client = Client::factory(env('RPC_SITE_HOST'));
+ $request = $client->request(
+ uniqid(),
+ '/separateaccounts/orderOnlineCompleted',
+ ['orderMainId' => 939,'userId'=>214]);
+ $response = $client->send($request);
+ dd($response->getBody()->getContents());
+ return $response->getBody()->getContents();
}
}
diff --git a/app/Libs/feier_print/api_php_demo.php b/app/Libs/feier_print/api_php_demo.php
index 4b8611c..9ad4fca 100644
--- a/app/Libs/feier_print/api_php_demo.php
+++ b/app/Libs/feier_print/api_php_demo.php
@@ -150,17 +150,29 @@ function signature($time)
function FeiePrint($order_num)
{
- $data = DB::table('ims_cjdc_order_main')
- ->alias('m')
- ->join(['ims_cjdc_order'=>'o'],'o.order_main_id = m.id','inner')
- ->join(['ims_cjdc_order_goods'=>'g'],'o.id = g.order_id','inner')
- ->join(['ims_cjdc_feprint'=>'f'],'m.market_id = f.market_id','inner')
- ->join(['ims_cjdc_store'=>'s'],'s.id = o.store_id','inner')
- //->distinct(true)
- ->where('m.order_num',$order_num)
- ->field("o.note as o_note,g.name,g.number,g.money,g.good_unit,m.delivery_time as ps_time,m.address,m.note,m.name as user_name,m.dada_fee,m.money as m_money,m.yhq_money2,m.box_money,f.sn,m.tel,m.order_num,g.id,g.spec,s.name as shopname")
- ->order('s.id')
- ->select();
+ //$data = DB::table('ims_cjdc_order_main')
+ // ->alias('m')
+ // ->join(['ims_cjdc_order'=>'o'],'o.order_main_id = m.id','inner')
+ // ->join(['ims_cjdc_order_goods'=>'g'],'o.id = g.order_id','inner')
+ // ->join(['ims_cjdc_feprint'=>'f'],'m.market_id = f.market_id','inner')
+ // ->join(['ims_cjdc_store'=>'s'],'s.id = o.store_id','inner')
+ // //->distinct(true)
+ // ->where('m.order_num',$order_num)
+ // ->field("o.note as o_note,g.name,g.number,g.money,g.good_unit,m.delivery_time as ps_time,m.address,m.note,m.name as user_name,m.dada_fee,m.money as m_money,m.yhq_money2,m.box_money,f.sn,m.tel,m.order_num,g.id,g.spec,s.name as shopname")
+ // ->order('s.id')
+ // ->select();
+
+ $data = Db::table('ims_cjdc_order_main as m')
+ ->join('ims_cjdc_order as o','o.order_main_id', '=', 'm.id','inner')
+ ->join('ims_cjdc_order_goods as g','o.id','=', 'g.order_id','inner')
+ ->join('ims_cjdc_feprint as f','m.market_id','=', 'f.market_id','inner')
+ ->join('ims_cjdc_store as s','s.id','=', 'o.store_id','inner')
+ ->where('m.global_order_id', $order_num)
+ ->selectRaw("o.note as o_note,g.name,g.number,g.money,g.good_unit,m.delivery_time as ps_time,m.address,m.note,m.name as user_name,m.dada_fee,m.money as m_money,m.yhq_money2,m.box_money,f.sn,m.tel,m.order_num,g.id,g.spec,s.name as shopname")
+ ->orderBy('s.id')
+ ->get()
+ ->toArray();
+
// $order_goods = Db::table('ims_cjdc_order_goods')->where('order_id', $order_main['id'])->field("name,number,money")->select();
// $sn = Db::table('ims_cjdc_feprint')->where('market_id', $order_main['market_id'])->value("sn");
$content = PrintFormat($data, 14, 6, 3, 6);
diff --git a/app/Models/ImsCjdcOrderMain.php b/app/Models/ImsCjdcOrderMain.php
index 8059d5b..382fa3a 100644
--- a/app/Models/ImsCjdcOrderMain.php
+++ b/app/Models/ImsCjdcOrderMain.php
@@ -33,6 +33,7 @@ class ImsCjdcOrderMain extends Model
{
$where = [];
$where['state'] = $state;
+ $where['updated_at'] = time();
if ($state==3) {
$where['receive_time'] = time();
}elseif ($state==4){
@@ -40,6 +41,7 @@ class ImsCjdcOrderMain extends Model
}elseif ($state==6){
$where['cancel_time'] = time();
}
+
return self::where('id',$oid)->update($where);
}
diff --git a/composer.json b/composer.json
index f795599..02919b2 100644
--- a/composer.json
+++ b/composer.json
@@ -12,6 +12,7 @@
"dcat/laravel-admin": "^1.6",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
+ "graze/guzzle-jsonrpc": "^3.2",
"guzzlehttp/guzzle": "^6.3",
"iidestiny/laravel-filesystem-oss": "^2.0",
"laravel/framework": "^7.0",
diff --git a/composer.lock b/composer.lock
index 655bd1c..044254b 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "b3d2ad98d7c44d90fdb1789d0ac90e0f",
+ "content-hash": "f3b2d7f14a9c18e3e5d2f479427ca20e",
"packages": [
{
"name": "aliyuncs/oss-sdk-php",
@@ -1003,6 +1003,71 @@
],
"time": "2020-04-28T08:47:37+00:00"
},
+ {
+ "name": "graze/guzzle-jsonrpc",
+ "version": "3.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/graze/guzzle-jsonrpc.git",
+ "reference": "c4513b7659534792b906723158a8388f54275a61"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/graze/guzzle-jsonrpc/zipball/c4513b7659534792b906723158a8388f54275a61",
+ "reference": "c4513b7659534792b906723158a8388f54275a61",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "require": {
+ "guzzlehttp/guzzle": "^6.0",
+ "guzzlehttp/promises": "^1.0",
+ "php": ">=5.5",
+ "psr/http-message": "^1.0"
+ },
+ "require-dev": {
+ "adlawson/timezone": "~1.0",
+ "fabpot/php-cs-fixer": "~0.5",
+ "mockery/mockery": "~0.9",
+ "phpunit/phpunit": "~4.3"
+ },
+ "type": "library",
+ "autoload": {
+ "files": [
+ "src/functions_include.php"
+ ],
+ "psr-4": {
+ "Graze\\GuzzleHttp\\JsonRpc\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Graze tech team",
+ "homepage": "https://github.com/graze/guzzle-jsonrpc/graphs/contributors"
+ }
+ ],
+ "description": "JSON-RPC 2.0 client for Guzzle",
+ "homepage": "https://github.com/graze/guzzle-jsonrpc",
+ "keywords": [
+ "Guzzle",
+ "guzzlehttp",
+ "http",
+ "json",
+ "json-rpc",
+ "jsonrpc",
+ "ring",
+ "rpc"
+ ],
+ "time": "2016-02-16T15:18:21+00:00"
+ },
{
"name": "guzzlehttp/guzzle",
"version": "6.5.5",