Browse Source

订单分账

master
lanzu_qsy 5 years ago
parent
commit
a39115a304
  1. 32
      app/Admin/Common/Rpc.php
  2. 4
      app/Admin/Controllers/ImsCjdcOrderMainController.php
  3. 8
      app/Admin/Extensions/CheckRow.php
  4. 56
      app/Admin/Extensions/OrderPrint.php
  5. 33
      app/Admin/Extensions/OrderStateHandle.php
  6. 6
      app/Admin/Forms/SelectHorseman.php
  7. 13
      app/Http/Controllers/TestController.php
  8. 34
      app/Libs/feier_print/api_php_demo.php
  9. 2
      app/Models/ImsCjdcOrderMain.php
  10. 1
      composer.json
  11. 67
      composer.lock

32
app/Admin/Common/Rpc.php

@ -0,0 +1,32 @@
<?php
namespace App\Admin\Common;
use Graze\GuzzleHttp\JsonRpc\Client;
class Rpc
{
const SEPARATE_ACCOUNTS = "/separateaccounts/orderOnlineCompleted";
/**
* 订单完成时分账流水
* @param $oid
* @param $uid
* @return string
*/
public static function separateAccounts($oid,$uid){
$client = Client::factory(env('RPC_SITE_HOST'));
$request = $client->request(
uniqid(),
self::SEPARATE_ACCOUNTS,
['orderMainId' => $oid,'userId'=>$uid]);
$response = $client->send($request);
return $response->getBody()->getContents();
}
}

4
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('详情'));
});

8
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);
}
}

56
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');

33
app/Admin/Extensions/OrderStateHandle.php

@ -1,11 +1,13 @@
<?php
namespace App\Admin\Extensions;
use App\Admin\Common\Rpc;
use App\Models\ImsCjdcOrderMain;
use Dcat\Admin\Grid\Displayers\Modal;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Layout\Content;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class OrderStateHandle extends RowAction
{
@ -16,14 +18,10 @@ class OrderStateHandle extends RowAction
protected $content;
public function __construct($title=null,$state=null)
{
parent::__construct($title);
$this->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("<h1>hello world!</h1>");
}
}

6
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']);
}
/**

13
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();
}
}

34
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);

2
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);
}

1
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",

67
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",

Loading…
Cancel
Save