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 6433eed..4f4a340 100644
--- a/app/Admin/Controllers/ImsCjdcOrderMainController.php
+++ b/app/Admin/Controllers/ImsCjdcOrderMainController.php
@@ -34,7 +34,7 @@ class ImsCjdcOrderMainController extends AdminController
$grid->paginate(10);//每页展示数据10条
//$grid->id;
//$grid->user_id('用户信息');
- $grid->column('user_name','用户信息');
+ $grid->column('nick_name','用户信息');
$grid->order_num;
$grid->state('订单状态')
@@ -42,88 +42,38 @@ class ImsCjdcOrderMainController extends AdminController
->label([1=>'dark',2=>'danger',3=>'indigo',4=>'success']);
$grid->money;
$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){
- $state = $actions->row->state;
-
-
-
-
+ $state = $actions->row->state;
if ($state==2){
$actions->append(new OrderStateHandle('接单',3));
- $actions->append(new OrderPrint('打印'));
- }elseif ($state==31){
+ }elseif ($state==311){
$actions->append(new OrderStateHandle('完成',4));
$actions->append(new OrderPrint('打印'));
}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("拒绝 ");
- //$actions->append("同意");
-
-
});
- //$grid->column('详情')->modal('详情',function ()use ($grid){
- // return view('orderdetail',['id'=>2]);
- //
- //});
+
$grid->filter(function (Grid\Filter $filter) {
$filter->equal('id');
});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
$grid->disableViewButton();
$grid->disableEditButton();
$grid->disableDeleteButton();
-
-
-
-
-
-
-
});
}
diff --git a/app/Admin/Controllers/Type.php b/app/Admin/Controllers/Type.php
index 84a0751..621a7ed 100644
--- a/app/Admin/Controllers/Type.php
+++ b/app/Admin/Controllers/Type.php
@@ -35,4 +35,5 @@ class Type
const BALANCE_USER_TYPE_MM = 3; //市场经理提现类型
const BALANCE_USER_TYPE_CS = 4; //社区提现类型
const BALANCE_USER_TYPE_STORE= 5; //商户提现类型
+
}
diff --git a/app/Admin/Extensions/CheckRow.php b/app/Admin/Extensions/CheckRow.php
index 1c2cf65..5d5ca48 100644
--- a/app/Admin/Extensions/CheckRow.php
+++ b/app/Admin/Extensions/CheckRow.php
@@ -2,6 +2,7 @@
namespace App\Admin\Extensions;
use App\Admin\Forms\CouponTieForm;
+use App\Admin\Forms\SelectHorseman;
use App\Models\ImsCjdcOrderMain;
use App\Models\StoreAccount;
use Dcat\Admin\Grid\RowAction;
@@ -12,21 +13,26 @@ class CheckRow extends RowAction
{
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);
}
public function render()
{
- // 实例化表单类并传递自定义参数
- $form = CouponTieForm::make();
+ // 实例化表单类并传递自定义参数
+ $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 dfd49ee..dd2d1a4 100644
--- a/app/Admin/Forms/SelectHorseman.php
+++ b/app/Admin/Forms/SelectHorseman.php
@@ -2,11 +2,14 @@
namespace App\Admin\Forms;
+use App\Models\ImsCjdcOrderMain;
+use App\Models\LanzuServiceHorseman;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
class SelectHorseman extends Form
{
+
/**
* Handle the form request.
*
@@ -14,13 +17,18 @@ class SelectHorseman extends Form
*
* @return Response
*/
+ protected $orderId;
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()
{
- $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()
{
- return [
- 'name' => 'John Doe',
- 'email' => 'John.Doe@gmail.com',
- ];
+
}
+
}
diff --git a/app/Admin/Repositories/ImsCjdcOrderMain.php b/app/Admin/Repositories/ImsCjdcOrderMain.php
index 1005792..220a7ad 100644
--- a/app/Admin/Repositories/ImsCjdcOrderMain.php
+++ b/app/Admin/Repositories/ImsCjdcOrderMain.php
@@ -18,9 +18,9 @@ class ImsCjdcOrderMain extends EloquentRepository
public function get(Grid\Model $model)
{
$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')
- ->select('lanzu_order_main.*','u.name as user_name')
+ ->select('lanzu_order_main.*','lanzu_user.nick_name')
->where('type',1)
->orderBy('lanzu_order_main.id','desc');//只取线上订单数据
@@ -40,8 +40,8 @@ class ImsCjdcOrderMain extends EloquentRepository
$query = $query->toArray();
//如果订单状态为配送中 将state设置为31
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;
}
}
diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php
index da3348b..60f4a44 100644
--- a/app/Http/Controllers/TestController.php
+++ b/app/Http/Controllers/TestController.php
@@ -11,34 +11,19 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use App\Models\FinancialRecord;
+
+
class TestController extends BaseController
{
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()
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/ImsCjdcOrder.php b/app/Models/ImsCjdcOrder.php
index a88180f..6793cf7 100644
--- a/app/Models/ImsCjdcOrder.php
+++ b/app/Models/ImsCjdcOrder.php
@@ -22,4 +22,5 @@ class ImsCjdcOrder extends Model
return $this->hasOne('\App\Models\ImsCjdcStore','id','store_id');
}
+
}
diff --git a/app/Models/ImsCjdcOrderMain.php b/app/Models/ImsCjdcOrderMain.php
index c54c904..382fa3a 100644
--- a/app/Models/ImsCjdcOrderMain.php
+++ b/app/Models/ImsCjdcOrderMain.php
@@ -25,39 +25,29 @@ class ImsCjdcOrderMain extends Model
}
/**
- * 同时变更主订单和子订单状态,
+ * 变更订单状态,
* @param $oid //主订单id
* @param $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)
{
- return self::where('id',$oid)->update(['order_shipping_code'=>$type]);
+ return self::where('id',$oid)->update(['shipping_type'=>$type]);
}
}
diff --git a/app/Models/LanzuServiceHorseman.php b/app/Models/LanzuServiceHorseman.php
index 38017bc..f642743 100644
--- a/app/Models/LanzuServiceHorseman.php
+++ b/app/Models/LanzuServiceHorseman.php
@@ -13,4 +13,18 @@ class LanzuServiceHorseman extends Model
protected $table = 'lanzu_service_horseman';
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;
+ }
}
diff --git a/config/order.php b/config/order.php
index 23caf29..2602b05 100644
--- a/config/order.php
+++ b/config/order.php
@@ -6,7 +6,7 @@ return [
1=>'待付款',
2=>'待接单',
3=>'待发货',
- 31=>'配送中',//state==3&&order_shipping_code==1
+ 311=>'配送中',//state==3&&order_shipping_code==1&&horseman_id=true
4=>'已完成',
5=>'已评价',
6=>'已取消',