Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

semour / semour_admin

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • semour_admin
  • app
  • Admin
  • Controllers
  • OrderController.php
OrderController.php 11.6 KB
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
1 2 3 4
<?php

namespace App\Admin\Controllers;

孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
5
use App\Admin\Actions\OrderAuditAction;
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
6
use App\Admin\Actions\OrderCancelAction;
孙龙's avatar
订单相关
db787562
 
孙龙 committed 2 years ago
7
use App\Admin\Actions\OrderEditSatusAction;
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
8
use App\Admin\Actions\OrderReverseAuditAction;
孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
9
use App\Admin\Pages\OrderDetailPage;
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
10
use App\Models\Cms\CmsUser;
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
11
use App\Models\Order;
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
12
use App\Models\OrderPrice;
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
13 14 15 16 17
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
18
use Dcat\Admin\Widgets\Box;
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
19
use Dcat\Admin\Widgets\Dropdown;
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
20
use Illuminate\Support\Arr;
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
21 22 23 24 25


class OrderController extends AdminController
{

孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
26

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    /**
     * Index interface.
     *
     * @param  Content  $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->translation($this->translation())
            ->title($this->title())
            ->description($this->description()['index'] ?? trans('admin.list'))
            ->body($this->grid());


    }


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Order(), function (Grid $grid) {
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
53 54
            $grid->model()->with("scmUser")->orderBy('order_id', 'desc');
            $grid->fixColumns(1,2);//固定列
孙龙's avatar
订单详情修改
54cca012
 
孙龙 committed 2 years ago
55
//            $grid->showColumnSelector();//开启字段选择器功能
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
56 57 58 59 60
            // 在 display 回调中使用
            $grid->column('序号')->display(function () {
                return $this->_index + 1;
            });
            $grid->column('order_id',"ID");
孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
61
            $grid->column('order_sn')->width('120px')->display(function () {
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
62
                return '<a  target="_blank" iframe-extends=true iframe-tab=true href="/admin/order/page?order_id='.$this->order_id.'" >'.$this->order_sn.'</a>';
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
63
            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
64
            $grid->column('status')->using(admin_trans('order.options.status'))->sortable();
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
65 66 67 68 69
            $grid->column('company_name')->display(function ($company_name) {
                return $company_name ? $company_name : "-";
            });
            $grid->column('scmUser.user_sn',admin_trans('scm-user.options.user_sn'))->link(function () {
                return admin_url('smc_user/'.$this->user_id);
孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
70

孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
71 72 73
            });
            $grid->column('scmUser.name',admin_trans('scm-user.options.name'));
            $grid->column('order_amount')->help('订单详情里-结算信息的“运费”“支付手续费”“其他费用”为空时;应付金额一栏为“待确认”');
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
74
            $grid->column('order_pay_type')->using(admin_trans('order.options.order_pay_type'))->sortable();
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
75 76 77 78
            $grid->column('fukuanfangshi',"付款方式")->display(function () {
                return "---不知道--";
            });
            $grid->column('sale_name');
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
79 80
            $grid->column('order_remark')->limit(10);
            $grid->column('update_time')->sortable()->display(function ($update_time) {
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
81 82
                return intval($update_time) > 0 ? date("Y-m-d H:i:s",intval($update_time)) : "-";
            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
83
            $grid->column('create_time')->sortable()->display(function ($create_time) {
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
84 85
                return intval($create_time) > 0 ? date("Y-m-d H:i:s",intval($create_time)) : "-";
            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
86

孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
87 88 89



孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
90

孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
91
            $grid->showFilter();
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
92
            $grid->filter(function (Grid\Filter $filter) {
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
93
                $filter->expand(true);
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
94

孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
95 96 97 98 99 100 101 102 103 104 105 106
                $filter->whereBetween('create_time', function ($q) {
                    $start = strtotime($this->input['start'] ?? null);
                    $end = strtotime($this->input['end'] ?? null);
                    $q->whereBetween('create_time', [$start, $end]);
                })->datetime()->width(3);
                $filter->whereBetween('update_time', function ($q) {
                    $start = strtotime($this->input['start'] ?? null);
                    $end = strtotime($this->input['end'] ?? null);
                    $q->whereBetween('update_time', [$start, $end]);
                })->datetime()->width(3);
                $filter->startWith('company_name')->width(3);
                $filter->startWith('scmUser.user_sn',admin_trans('scm-user.fields.user_sn'))->width(3);
孙龙's avatar
订单列表
d6554ecf
 
孙龙 committed 2 years ago
107 108 109 110 111
                $filter->equal('status')->select([
                    "1"=>"待审核","2"=>"待付款","4"=>"待发货","8"=>"待收货","10"=>"交易成功","-1"=>"已取消"
                ])->width(3);
                $filter->equal('sales_id',trans('inquiry.fields.sales_name'))->select(CmsUser::pluck('name', 'userId')->where("status",0)->toArray())->width(3);

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
112
            });
孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
113 114 115 116


            $grid->tools([
                new OrderAuditAction(),
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
117
                new OrderReverseAuditAction(),
孙龙's avatar
订单相关
db787562
 
孙龙 committed 2 years ago
118
                new OrderEditSatusAction(),
孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
119 120 121
            ]);


孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
122 123 124 125 126 127 128 129 130 131 132
            $grid->setActionClass(Grid\Displayers\Actions::class);
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();

                // 当前行的数据数组
                $rowArray = $actions->row->toArray();
                // 获取当前行主键值
                $id = $actions->getKey();
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
133
                //取消按钮
孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
134 135 136 137
                if(in_array($rowArray["status"],[1,2])){
                    $actions->append(new OrderCancelAction());
                }

孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
138

孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
139
                //下载
孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
140 141 142 143 144 145 146 147 148 149 150 151 152 153
                if($rowArray["status"] >= 2){
                    $options = [
                        'PI',
                    ];
                    if($rowArray["status"] > 2){
                        array_push($options,"CI","PL");
                    }
                    $actions->prepend(
                        \App\Admin\Controllers\OrderController::down($id,$options)
                    );
                }



孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
154 155
            });

孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
156 157 158 159




孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
160
        });
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
161

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
162 163
    }

孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
164
    public static function down($id,$optoins=[]){
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
165 166 167 168

        $menu1 =  Dropdown::make()
            ->button('下载')
            ->buttonClass('btn btn-primary btn-sm btn-mini') // 设置按钮样式
孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
169
            ->options($optoins)->map(function ($v, $k) use($id) {
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
                $k++;
                return "<a style='min-width: 5rem' class='test_item' data-orderid='$id' data-id='$k', data-value='{$v}' data-test='Hello world.' href='javascript:void(0)'>$v</a>";
            });

        \Dcat\Admin\Admin::style(
            <<<style
.dropdown .dropdown-menu {min-width: 5rem;}
style

        );
        \Dcat\Admin\Admin::script(
            <<<JS
$('.test_item').click(function () {
        console.log($(this).data().id);
        window.location.href="/admin/api/order_download?type="+$(this).data().id+"&order_id="+$(this).data().orderid
});
JS
        );

        return $menu1;
    }

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Order(), function (Show $show) {
            $show->field('order_id');
            $show->field('order_sn');
            $show->field('order_remark');
            $show->field('company_name');
            $show->field('order_type');
            $show->field('order_source');
            $show->field('order_pay_type');
            $show->field('user_id');
            $show->field('order_amount');
            $show->field('advance_amount');
            $show->field('currency');
            $show->field('create_time');
            $show->field('sale_id');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Order(), function (Form $form) {
            $form->display('order_id');
            $form->text('order_sn');
            $form->text('order_remark');
            $form->text('company_name');
            $form->text('order_type');
            $form->text('order_source');
            $form->text('order_pay_type');
            $form->text('user_id');
            $form->text('order_amount');
            $form->text('advance_amount');
            $form->text('currency');
            $form->text('create_time');
            $form->text('sale_id');
        });
    }
孙龙's avatar
订单列表
ddba0583
 
孙龙 committed 2 years ago
241

孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
242
    public function page(Content $content){
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
243 244 245 246
        $params = request()->all();
        $order_id = arrayGet($params,"order_id",0,"intval");

        $orderInfo = Order::getOneAndRelationList($order_id);
孙龙's avatar
订单详情修改
54cca012
 
孙龙 committed 2 years ago
247
        $orderItems = $orderInfo["order_items"]??[];
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
        $info=[];
//        $info["orderInfo"] = $orderInfo;

        //基本信息
        $info["baseInfo"]["order_sn"] = $orderInfo["order_sn"];
        $info["baseInfo"]["status"] = $orderInfo["status"];
        $info["baseInfo"]["status_cn"] = Arr::get(array_flip(Order::$STATUS_FORAMT),$orderInfo["status"],"");
        $info["baseInfo"]["company_name"] = $orderInfo["company_name"];
        $info["baseInfo"]["user_sn"] = $orderInfo["scm_user"]["user_sn"]??"";
        $info["baseInfo"]["name"] = $orderInfo["scm_user"]["name"]??"";


        $info["receiveInfo"] = [];//收货信息
        $info["billingInfo"] = [];//账单信息

        $addressList = $orderInfo["order_address"]??[];
        foreach($addressList as $addressItem){
            if($addressItem["order_address_type"] == "1"){
                $info["receiveInfo"] = $addressItem;
            }elseif($addressItem["order_address_type"] == "2"){
                $info["billingInfo"] = $addressItem;
            }
        }



        $orderInfo["orderItemList"] = $orderItems;
        foreach($orderInfo["orderItemList"] as $k=>$item){
            $orderInfo["orderItemList"][$k]["goods_price_format"] = decimal_number_format_usd($item["goods_price"]);
            $orderInfo["orderItemList"][$k]["total_amount"] = decimal_number_format($item["goods_price"]*$item["goods_number"]);
            $orderInfo["orderItemList"][$k]["total_amount_format"] = decimal_number_format_usd($item["goods_price"]*$item["goods_number"]);
        }


        //结算信息
        $info["settlementInfo"]=[];
        $orderPrice = $orderInfo["order_price"]??[];
        $info["settlementInfo"]["order_amount"] = $orderInfo["order_amount"];
        $info["settlementInfo"]["order_amount_format"] = decimal_number_format_usd($orderInfo["order_amount"]);
        $info["settlementInfo"]["order_freight_amount"] = 0;//运费
        $info["settlementInfo"]["order_freight_amount_format"] = "";
        $info["settlementInfo"]["order_pay_commission_amount"] = 0;//手续费
        $info["settlementInfo"]["order_pay_commission_amount_format"] = "";
孙龙's avatar
订单详情修改
54cca012
 
孙龙 committed 2 years ago
291
//        $orderItemsId = Arr::pluck($orderItems,"rec_id");
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312

        foreach($orderPrice as $orderPriceItem){
            switch ($orderPriceItem["price_type"]){
                case OrderPrice::$PRICE_TYPE_LIST["运费"]:
                    $info["settlementInfo"]["order_freight_amount"] = $orderPriceItem["price"];
                    $info["settlementInfo"]["order_freight_amount_format"] = decimal_number_format_usd($orderPriceItem["price"]);
                case OrderPrice::$PRICE_TYPE_LIST["支付手续费"]:
                    $info["settlementInfo"]["order_pay_commission_amount"] = $orderPriceItem["price"];
                    $info["settlementInfo"]["order_pay_commission_amount_format"] = decimal_number_format_usd($orderPriceItem["price"]);
            }
        }
        $info["settlementInfo"]["order_total_amount"] = $info["settlementInfo"]["order_amount"] + $info["settlementInfo"]["order_freight_amount"]+$info["settlementInfo"]["order_pay_commission_amount"];
        $info["settlementInfo"]["order_total_amount_format"] = decimal_number_format_usd($info["settlementInfo"]["order_total_amount"]);





dump($info);

        return view('admin.pages.order-page',["info"=>$info]);
孙龙's avatar
详情打开新窗口
16b9effe
 
孙龙 committed 2 years ago
313

孙龙's avatar
订单列表
ddba0583
 
孙龙 committed 2 years ago
314
    }
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
315
}