Browse Source

Merge branch 'qs_local_order' into develop

# Conflicts:
#	app/Admin/Controllers/Test.php
#	composer.lock
master
lanzu_qsy 6 years ago
parent
commit
6e2ed43f0f
  1. 32
      app/Admin/Common/Rpc.php
  2. 74
      app/Admin/Controllers/ImsCjdcOrderMainController.php
  3. 1
      app/Admin/Controllers/Type.php
  4. 12
      app/Admin/Extensions/CheckRow.php
  5. 56
      app/Admin/Extensions/OrderPrint.php
  6. 33
      app/Admin/Extensions/OrderStateHandle.php
  7. 32
      app/Admin/Forms/SelectHorseman.php
  8. 8
      app/Admin/Repositories/ImsCjdcOrderMain.php
  9. 35
      app/Http/Controllers/TestController.php
  10. 34
      app/Libs/feier_print/api_php_demo.php
  11. 1
      app/Models/ImsCjdcOrder.php
  12. 38
      app/Models/ImsCjdcOrderMain.php
  13. 14
      app/Models/LanzuServiceHorseman.php
  14. 2
      config/order.php

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

74
app/Admin/Controllers/ImsCjdcOrderMainController.php

@ -34,7 +34,7 @@ class ImsCjdcOrderMainController extends AdminController
$grid->paginate(10);//每页展示数据10条 $grid->paginate(10);//每页展示数据10条
//$grid->id; //$grid->id;
//$grid->user_id('用户信息'); //$grid->user_id('用户信息');
$grid->column('user_name','用户信息');
$grid->column('nick_name','用户信息');
$grid->order_num; $grid->order_num;
$grid->state('订单状态') $grid->state('订单状态')
@ -42,88 +42,38 @@ class ImsCjdcOrderMainController extends AdminController
->label([1=>'dark',2=>'danger',3=>'indigo',4=>'success']); ->label([1=>'dark',2=>'danger',3=>'indigo',4=>'success']);
$grid->money; $grid->money;
$grid->column('market.name','所属市场'); $grid->column('market.name','所属市场');
$grid->time;
$grid->pay_time;
$grid->actions(new CheckRow('自送'));
$grid->column('配送方式')
->if(function ($column){
if ($this->state==3){
return true;
}
return false;
})
->display('站内自送')
->modal('站内自送',function ($modal){
return CouponTieForm::make();
})
->else()
->display('站内自送');
$grid->pay_time('支付时间')->display(function (){
return date('Y-m-d H:i:s');
});
$grid->created_at('下单时间')->display(function (){
return date('Y-m-d H:i:s');
});
$grid->actions(function (Grid\Displayers\Actions $actions) use ($grid){ $grid->actions(function (Grid\Displayers\Actions $actions) use ($grid){
$state = $actions->row->state;
$state = $actions->row->state;
if ($state==2){ if ($state==2){
$actions->append(new OrderStateHandle('接单',3)); $actions->append(new OrderStateHandle('接单',3));
$actions->append(new OrderPrint('打印'));
}elseif ($state==31){
}elseif ($state==311){
$actions->append(new OrderStateHandle('完成',4)); $actions->append(new OrderStateHandle('完成',4));
$actions->append(new OrderPrint('打印')); $actions->append(new OrderPrint('打印'));
}elseif ($state==3){ }elseif ($state==3){
$actions->append(new OrderStateHandle('站内自送',30));
$actions->append(new OrderPrint('打印'));
$actions->append(new CheckRow($actions->row->id,$grid->model()->getCurrentPage(),'自送'));
} }
$actions->append(new OrderDetail('详情')); $actions->append(new OrderDetail('详情'));
//$actions->append("<a class='btn btn-xs action-btn btn-danger grid-row-refuse' data-id='{$actions->getKey()}'><i class='fa fa-close' title='拒绝退款'>拒绝</i></a>&nbsp;&nbsp;");
//$actions->append("<a class='btn btn-xs action-btn btn-success grid-row-pass' data-id='{$actions->getKey()}'><i class='fa fa-check' title='同意退款'>同意</i></a>");
}); });
//$grid->column('详情')->modal('详情',function ()use ($grid){
// return view('orderdetail',['id'=>2]);
//
//});
$grid->filter(function (Grid\Filter $filter) { $grid->filter(function (Grid\Filter $filter) {
$filter->equal('id'); $filter->equal('id');
}); });
$grid->disableViewButton(); $grid->disableViewButton();
$grid->disableEditButton(); $grid->disableEditButton();
$grid->disableDeleteButton(); $grid->disableDeleteButton();
}); });
} }

1
app/Admin/Controllers/Type.php

@ -35,4 +35,5 @@ class Type
const BALANCE_USER_TYPE_MM = 3; //市场经理提现类型 const BALANCE_USER_TYPE_MM = 3; //市场经理提现类型
const BALANCE_USER_TYPE_CS = 4; //社区提现类型 const BALANCE_USER_TYPE_CS = 4; //社区提现类型
const BALANCE_USER_TYPE_STORE= 5; //商户提现类型 const BALANCE_USER_TYPE_STORE= 5; //商户提现类型
} }

12
app/Admin/Extensions/CheckRow.php

@ -2,6 +2,7 @@
namespace App\Admin\Extensions; namespace App\Admin\Extensions;
use App\Admin\Forms\CouponTieForm; use App\Admin\Forms\CouponTieForm;
use App\Admin\Forms\SelectHorseman;
use App\Models\ImsCjdcOrderMain; use App\Models\ImsCjdcOrderMain;
use App\Models\StoreAccount; use App\Models\StoreAccount;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
@ -12,21 +13,26 @@ class CheckRow extends RowAction
{ {
protected $title; protected $title;
public function __construct($title=null)
protected $order_id;
protected $currentPage;
public function __construct($orderId,$currentPage,$title=null)
{ {
$this->order_id = $orderId;
$this->currentPage = $currentPage;
parent::__construct($title); parent::__construct($title);
} }
public function render() public function render()
{ {
// 实例化表单类并传递自定义参数
$form = CouponTieForm::make();
// 实例化表单类并传递自定义参数
$form = SelectHorseman::make(['order_id'=>$this->order_id,'current_page'=>$this->currentPage]);
return Modal::make() return Modal::make()
->lg() ->lg()
->title($this->title) ->title($this->title)
->body($form) ->body($form)
->button($this->title); ->button($this->title);
} }
} }

56
app/Admin/Extensions/OrderPrint.php

@ -7,12 +7,14 @@ namespace App\Admin\Extensions;
use App\Models\Feprint; use App\Models\Feprint;
use App\Models\ImsCjdcOrderMain; use App\Models\ImsCjdcOrderMain;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use Graze\GuzzleHttp\JsonRpc\Client;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class OrderPrint extends RowAction class OrderPrint extends RowAction
{ {
protected $title; protected $title;
public function __construct($title=null)
public function __construct($title = null)
{ {
parent::__construct($title); parent::__construct($title);
@ -20,9 +22,14 @@ class OrderPrint extends RowAction
public function handle(Request $request) 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); $row = ImsCjdcOrderMain::find($oid);
//>>1.获取打印机状态 //>>1.获取打印机状态
$result = $this->getPrintStatus($row->market_id); $result = $this->getPrintStatus($row->market_id);
//>>2.调用打印 //>>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 * @return int
*/ */
public function getPrintStatus($mid) 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; 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) public function feiErPrint($order_num)
{ {
include_once app_path('Libs\feier_print\api_php_demo.php'); include_once app_path('Libs\feier_print\api_php_demo.php');

33
app/Admin/Extensions/OrderStateHandle.php

@ -1,11 +1,13 @@
<?php <?php
namespace App\Admin\Extensions; namespace App\Admin\Extensions;
use App\Admin\Common\Rpc;
use App\Models\ImsCjdcOrderMain; use App\Models\ImsCjdcOrderMain;
use Dcat\Admin\Grid\Displayers\Modal; use Dcat\Admin\Grid\Displayers\Modal;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Layout\Content; use Dcat\Admin\Layout\Content;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class OrderStateHandle extends RowAction class OrderStateHandle extends RowAction
{ {
@ -16,14 +18,10 @@ class OrderStateHandle extends RowAction
protected $content; protected $content;
public function __construct($title=null,$state=null) public function __construct($title=null,$state=null)
{ {
parent::__construct($title); parent::__construct($title);
$this->state = $state; $this->state = $state;
} }
/** /**
* 处理请求 * 处理请求
* *
@ -37,19 +35,18 @@ class OrderStateHandle extends RowAction
$id = $this->getKey(); $id = $this->getKey();
$orderMain = new ImsCjdcOrderMain(); $orderMain = new ImsCjdcOrderMain();
$state = $request->get('state'); $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){ if ($res==true){
return $this->response()->success('操作成功')->refresh(); return $this->response()->success('操作成功')->refresh();
}else{ }else{
@ -69,8 +66,4 @@ class OrderStateHandle extends RowAction
]; ];
} }
public function showForm(Content $content)
{
return $content->title('站内自送')->body("<h1>hello world!</h1>");
}
} }

32
app/Admin/Forms/SelectHorseman.php

@ -2,11 +2,14 @@
namespace App\Admin\Forms; namespace App\Admin\Forms;
use App\Models\ImsCjdcOrderMain;
use App\Models\LanzuServiceHorseman;
use Dcat\Admin\Widgets\Form; use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
class SelectHorseman extends Form class SelectHorseman extends Form
{ {
/** /**
* Handle the form request. * Handle the form request.
* *
@ -14,13 +17,18 @@ class SelectHorseman extends Form
* *
* @return Response * @return Response
*/ */
protected $orderId;
public function handle(array $input) public function handle(array $input)
{ {
// dump($input);
// return $this->error('Your error message.');
return $this->success('Processed successfully.', '/');
$hid = request()->get('horseman_id');
$oid = request()->get('order_id');
$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?page={$current_page}");
}else{
return $this->error('操作失败');
}
} }
/** /**
@ -28,8 +36,12 @@ class SelectHorseman extends Form
*/ */
public function form() public function form()
{ {
$this->text('name')->required();
$this->email('email')->rules('email');
$this->select('horseman_id','配送员')
->options(LanzuServiceHorseman::getHorseman())
->required();
$this->hidden('order_id')->value($this->data['order_id']);
$this->hidden('current_page')->value($this->data['current_page']);
} }
/** /**
@ -39,9 +51,7 @@ class SelectHorseman extends Form
*/ */
public function default() public function default()
{ {
return [
'name' => 'John Doe',
'email' => 'John.Doe@gmail.com',
];
} }
} }

8
app/Admin/Repositories/ImsCjdcOrderMain.php

@ -18,9 +18,9 @@ class ImsCjdcOrderMain extends EloquentRepository
public function get(Grid\Model $model) public function get(Grid\Model $model)
{ {
$builder = new \App\Models\ImsCjdcOrderMain(); $builder = new \App\Models\ImsCjdcOrderMain();
$builder = $builder::leftJoin('ims_cjdc_user as u','u.id','lanzu_order_main.user_id')
$builder = $builder::leftJoin('lanzu_user','lanzu_user.id','lanzu_order_main.user_id')
->with('market') ->with('market')
->select('lanzu_order_main.*','u.name as user_name')
->select('lanzu_order_main.*','lanzu_user.nick_name')
->where('type',1) ->where('type',1)
->orderBy('lanzu_order_main.id','desc');//只取线上订单数据 ->orderBy('lanzu_order_main.id','desc');//只取线上订单数据
@ -40,8 +40,8 @@ class ImsCjdcOrderMain extends EloquentRepository
$query = $query->toArray(); $query = $query->toArray();
//如果订单状态为配送中 将state设置为31 //如果订单状态为配送中 将state设置为31
foreach ($query['data'] as &$value){ foreach ($query['data'] as &$value){
if ($value['state']==3&&$value['shipping_type']==1){
$value['state'] = 31;
if ($value['state']==3&&$value['shipping_type']==1&&!empty($value['horseman_id'])){
$value['state'] = 311;
} }
} }

35
app/Http/Controllers/TestController.php

@ -11,34 +11,19 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\Models\FinancialRecord; use App\Models\FinancialRecord;
class TestController extends BaseController class TestController extends BaseController
{ {
public function Test(){ public function Test(){
$ret = null;
// dump(FinancialRecord::where('id',1));
// $ret = FinancialRecord::getFinancialRecordModel(1);
// $s = $ret::where('id',1)->first();
// dump($s);
// $ret = FinancialRecord::getFinancialRecordModel(2);
// $s = $ret::where('id',1)->first();
// dump($s);
// $ret = FinancialRecord::getFinancialRecordModel(3);
// $s = $ret::where('id',1)->first();
// dump($s);
// $ret = FinancialRecord::getFinancialRecordModel(4);
// $s = $ret::where('id',1)->first();
// dump($s);
$ret = FinancialRecord::getFinancialRecordModel(5);
$s = $ret::where('id',1)->first();
dump($s);
return 1;
$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();
} }
public function testRpc() public function testRpc()

34
app/Libs/feier_print/api_php_demo.php

@ -150,17 +150,29 @@ function signature($time)
function FeiePrint($order_num) 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(); // $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"); // $sn = Db::table('ims_cjdc_feprint')->where('market_id', $order_main['market_id'])->value("sn");
$content = PrintFormat($data, 14, 6, 3, 6); $content = PrintFormat($data, 14, 6, 3, 6);

1
app/Models/ImsCjdcOrder.php

@ -22,4 +22,5 @@ class ImsCjdcOrder extends Model
return $this->hasOne('\App\Models\ImsCjdcStore','id','store_id'); return $this->hasOne('\App\Models\ImsCjdcStore','id','store_id');
} }
} }

38
app/Models/ImsCjdcOrderMain.php

@ -25,39 +25,29 @@ class ImsCjdcOrderMain extends Model
} }
/** /**
* 同时变更主订单和子订单状态,
* 变更订单状态,
* @param $oid //主订单id * @param $oid //主订单id
* @param $state //订单状态 * @param $state //订单状态
*/ */
public function modifyState($oid,$state) public function modifyState($oid,$state)
{ {
return DB::transaction(function () use ($oid,$state){
$data1['state'] = $data2['state'] = $state;
$data1['update_time'] = time();
if ($state == 4) {
$data1['complete_time'] = $data2['complete_time'] = time();
} elseif ($state == 3) {
$data1['jd_time'] = $data2['jd_time'] = time();
}
DB::table('ims_cjdc_order_main')
->where('id',$oid)
->update($data1);
DB::table('ims_cjdc_order')
->where('order_main_id',$oid)
->update($data2);
if ($state==4){
//添加店铺流水记录
$account = new StoreAccount();
$account->addStoreAccount($oid);
}
return true;
});
$where = [];
$where['state'] = $state;
$where['updated_at'] = time();
if ($state==3) {
$where['receive_time'] = time();
}elseif ($state==4){
$where['complete_time'] = time();
}elseif ($state==6){
$where['cancel_time'] = time();
}
return self::where('id',$oid)->update($where);
} }
public function updateShippingType($oid,$type) public function updateShippingType($oid,$type)
{ {
return self::where('id',$oid)->update(['order_shipping_code'=>$type]);
return self::where('id',$oid)->update(['shipping_type'=>$type]);
} }
} }

14
app/Models/LanzuServiceHorseman.php

@ -13,4 +13,18 @@ class LanzuServiceHorseman extends Model
protected $table = 'lanzu_service_horseman'; protected $table = 'lanzu_service_horseman';
protected $dateFormat = 'U'; protected $dateFormat = 'U';
public static function getHorseman($marketId=null)
{
if ($marketId){
$rows = self::where('market_id',$marketId)->get();
}else{
$rows = self::get();
}
$item = [];
foreach ($rows as $row) {
$item[$row->id] = $row->name;
}
return $item;
}
} }

2
config/order.php

@ -6,7 +6,7 @@ return [
1=>'待付款', 1=>'待付款',
2=>'待接单', 2=>'待接单',
3=>'待发货', 3=>'待发货',
31=>'配送中',//state==3&&order_shipping_code==1
311=>'配送中',//state==3&&order_shipping_code==1&&horseman_id=true
4=>'已完成', 4=>'已完成',
5=>'已评价', 5=>'已评价',
6=>'已取消', 6=>'已取消',

Loading…
Cancel
Save