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 12.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
权限
aa344e0e
 
孙龙 committed 2 years ago
10
use App\Admin\Service\PermService;
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
11
use App\Models\Cms\CmsUser;
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
12
use App\Models\Order;
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
13
use App\Models\OrderPrice;
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
14 15 16 17 18
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
19
use Dcat\Admin\Widgets\Box;
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
20
use Dcat\Admin\Widgets\Dropdown;
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
21
use Illuminate\Support\Arr;
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
22 23 24 25 26


class OrderController extends AdminController
{

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

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
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()
    {
孙龙's avatar
权限
aa344e0e
 
孙龙 committed 2 years ago
53 54
        $user = request()->user;
//        dump(PermService::getUserPerms());
孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
55
        return Grid::make(new Order(), function (Grid $grid) {
孙龙's avatar
订单bug修改
ff758472
 
孙龙 committed 2 years ago
56
            $grid->model()->rule(Order::$ruleViewList)->with("scmUser")->with("order_price")->orderBy('order_id', 'desc');
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
57
            $grid->fixColumns(1,2);//固定列
孙龙's avatar
订单详情修改
54cca012
 
孙龙 committed 2 years ago
58
//            $grid->showColumnSelector();//开启字段选择器功能
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
59 60 61 62 63
            // 在 display 回调中使用
            $grid->column('序号')->display(function () {
                return $this->_index + 1;
            });
            $grid->column('order_id',"ID");
孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
64
            $grid->column('order_sn')->width('120px')->display(function () {
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
65
                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
66
            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
67
            $grid->column('status')->using(admin_trans('order.options.status'))->sortable();
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
68 69 70
            $grid->column('company_name')->display(function ($company_name) {
                return $company_name ? $company_name : "-";
            });
孙龙's avatar
订单相关翻译
e5d8751f
 
孙龙 committed 2 years ago
71
            $grid->column('scmUser.user_sn',admin_trans('scm-user.fields.user_sn'))->link(function () {
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
72
                return admin_url('smc_user/'.$this->user_id);
孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
73

孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
74
            });
孙龙's avatar
订单相关翻译
e5d8751f
 
孙龙 committed 2 years ago
75
            $grid->column('scmUser.name',admin_trans('scm-user.fields.name'));
孙龙's avatar
订单bug修改
ff758472
 
孙龙 committed 2 years ago
76 77 78 79 80 81 82 83 84 85 86

            $grid->column('order_price',"应付金额")->display(function ($order_price) {
                $otherAmount = 0;
                foreach($order_price->toArray() as $key=>$val ){
                    if(in_array($val["price_type"],[3,5])){
                        $otherAmount +=    $val["price"];
                    }
                }
                if($otherAmount == 0){
                    return "待确认";
                }else{
孙龙's avatar
订单合同
2b3964d0
 
孙龙 committed 2 years ago
87
                    return decimal_number_format_usd($this->order_amount+$otherAmount);
孙龙's avatar
订单bug修改
ff758472
 
孙龙 committed 2 years ago
88 89 90 91
                }


            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
92
            $grid->column('order_pay_type')->using(admin_trans('order.options.order_pay_type'))->sortable();
孙龙's avatar
订单相关翻译
e5d8751f
 
孙龙 committed 2 years ago
93 94
            $grid->column('order_user_pay_type',admin_trans("order.fields.order_user_pay_type"))->display(function () {
                return Arr::get(admin_trans("order.options.order_user_pay_type"),$this->order_user_pay_type,"");
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
95 96
            });
            $grid->column('sale_name');
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
97 98
            $grid->column('order_remark')->limit(10);
            $grid->column('update_time')->sortable()->display(function ($update_time) {
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
99 100
                return intval($update_time) > 0 ? date("Y-m-d H:i:s",intval($update_time)) : "-";
            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
101
            $grid->column('create_time')->sortable()->display(function ($create_time) {
孙龙's avatar
订单
5d9879bd
 
孙龙 committed 2 years ago
102 103
                return intval($create_time) > 0 ? date("Y-m-d H:i:s",intval($create_time)) : "-";
            });
孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
104

孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
105 106 107



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

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

孙龙's avatar
订单
99f65a05
 
孙龙 committed 2 years ago
113 114 115 116 117 118 119 120 121 122 123 124
                $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
中英文翻译
2f378093
 
孙龙 committed 2 years ago
125
                $filter->equal('status')->select(admin_trans("order.options.status_search"))->width(3);
孙龙's avatar
订单列表
d6554ecf
 
孙龙 committed 2 years ago
126 127
                $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
128
            });
孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
129 130 131 132


            $grid->tools([
                new OrderAuditAction(),
孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
133
                new OrderReverseAuditAction(),
孙龙's avatar
订单相关
db787562
 
孙龙 committed 2 years ago
134
                new OrderEditSatusAction(),
孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
135 136 137
            ]);


孙龙's avatar
订单列表
53aaa2c7
 
孙龙 committed 2 years ago
138 139 140 141 142 143 144 145 146 147 148
            $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
149
                //取消按钮
孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
150 151 152 153
                if(in_array($rowArray["status"],[1,2])){
                    $actions->append(new OrderCancelAction());
                }

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

孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
155
                //下载
孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
156 157 158 159 160 161 162 163 164 165 166 167 168 169
                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
170 171
            });

孙龙's avatar
弹框操作
75ad5f14
 
孙龙 committed 2 years ago
172 173 174 175




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

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
178 179
    }

孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
180
    public static function down($id,$optoins=[]){
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
181 182 183 184

        $menu1 =  Dropdown::make()
            ->button('下载')
            ->buttonClass('btn btn-primary btn-sm btn-mini') // 设置按钮样式
孙龙's avatar
订单取消 和 审核
45e72bdc
 
孙龙 committed 2 years ago
185
            ->options($optoins)->map(function ($v, $k) use($id) {
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
186 187 188 189 190 191 192 193 194 195 196 197 198 199
                $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);
孙龙's avatar
合同
52d31465
 
孙龙 committed 2 years ago
200
        window.location.href="/api/order_download?type="+$(this).data().id+"&order_id="+$(this).data().orderid
孙龙's avatar
订单列表
c7b03ea4
 
孙龙 committed 2 years ago
201 202 203 204 205 206 207
});
JS
        );

        return $menu1;
    }

孙龙's avatar
init
3795d857
 
孙龙 committed 2 years ago
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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    /**
     * 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
257

孙龙's avatar
订单详情
8b9685de
 
孙龙 committed 2 years ago
258
    public function page(Content $content){
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
259 260 261 262
        $params = request()->all();
        $order_id = arrayGet($params,"order_id",0,"intval");

        $orderInfo = Order::getOneAndRelationList($order_id);
孙龙's avatar
订单详情修改
54cca012
 
孙龙 committed 2 years ago
263
        $orderItems = $orderInfo["order_items"]??[];
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
264 265 266 267 268 269
        $info=[];
//        $info["orderInfo"] = $orderInfo;

        //基本信息
        $info["baseInfo"]["order_sn"] = $orderInfo["order_sn"];
        $info["baseInfo"]["status"] = $orderInfo["status"];
孙龙's avatar
翻译
8bbbe1db
 
孙龙 committed 2 years ago
270
        $info["baseInfo"]["status_cn"] = Arr::get(admin_trans("order.options.status"),$orderInfo["status"],"");
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
        $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
307
//        $orderItemsId = Arr::pluck($orderItems,"rec_id");
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
308 309 310 311 312 313 314 315 316 317 318 319 320 321

        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"]);

孙龙's avatar
订单详情
2f63c767
 
孙龙 committed 2 years ago
322
        $info["settlementInfo"]["order_user_pay_type"] = $orderInfo["order_user_pay_type"];
孙龙's avatar
订单详情
7fb12613
 
孙龙 committed 2 years ago
323
        $info["settlementInfo"]["order_user_pay_type_cn"] = Arr::get(array_flip(Order::$ORDER_USER_PAY_TYPE),$orderInfo["order_user_pay_type"],"");
孙龙's avatar
订单详情
2f63c767
 
孙龙 committed 2 years ago
324

孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
325

孙龙's avatar
中英文翻译 -》 订单
82d8f8f7
 
孙龙 committed 2 years ago
326
        $info["translation"]=admin_trans("order.order_page_list");
孙龙's avatar
订单详情
afd24318
 
孙龙 committed 2 years ago
327 328


孙龙's avatar
中英文
b658ea7c
 
孙龙 committed 2 years ago
329 330
        $lang = $GLOBALS["app"]["config"]["admin"]["lang"] ?? "";
        $info["lang"] = $lang == "zh_CN" ? 1 : 2;
孙龙's avatar
订单相关
4396caee
 
孙龙 committed 2 years ago
331 332 333 334
        $info["lang_str"] = $lang;
//        dump($info);
//        dd(user_admin_config("lang"));

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

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