afa 10 сар өмнө
parent
commit
2de92fb511

+ 62 - 3
application/admin/controller/offline/Order.php

@@ -3,7 +3,11 @@
 namespace app\admin\controller\offline;
 
 use app\common\controller\Backend;
-
+use Exception;
+use think\Db;
+use app\common\model\UserArea;
+use think\exception\DbException;
+use think\exception\ValidateException;
 /**
  * 订单管理
  *
@@ -22,7 +26,6 @@ class Order extends Backend
     {
         parent::_initialize();
         $this->model = new \app\common\model\ProductOrder();
-
     }
 
     /**
@@ -49,7 +52,7 @@ class Order extends Backend
             return $this->selectpage();
         }
         [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        $list = $this->model->with('users,products,areas')
+        $list = $this->model->with('users,products,areas,address')
             ->where($where)
             ->order($sort, $order)
             ->paginate($limit);
@@ -57,4 +60,60 @@ class Order extends Backend
         return json($result);
     }
 
+
+    /**
+     * 发货
+     * @param $ids
+     * @return string|void
+     * @throws \think\Exception
+     * @throws \think\exception\DbException
+     */
+    public function shipping($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+ 
+        if (false === $this->request->isPost()) {
+            
+            $area = UserArea::where('order_id', $ids)->find();
+            $this->view->assign('row', $row);
+            $this->view->assign('area', $area);
+            return $this->view->fetch();
+        }
+
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $params = $this->preExcludeFields($params);
+        $result = false;
+        Db::startTrans();
+        try {
+            //是否采用模型验证
+            if ($this->modelValidate) {
+                $name     = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                $row->validateFailException()->validate($validate);
+            }
+            if(empty($params['tracking_no'])) throw new ValidateException('请添加快递单号');
+            $result = UserArea::where('id', $params['area_id'])->where('status', UserArea::Waiting)->update([
+                'status'        => UserArea::Shipped,
+                'tracking_no'   => $params['tracking_no']
+            ]);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
+    }
 }

+ 45 - 0
application/admin/view/offline/order/shipping.html

@@ -0,0 +1,45 @@
+<form id="edit-form"  role="form" data-toggle="validator" method="POST" action="">
+      <div class="form-horizontal">
+      <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">用户ID:</label>
+            <div class="col-xs-12 col-sm-8">
+                  <label class="control-label col-xs-12 col-sm-2">{$row.user_id}</label>
+            </div>
+      </div>
+      <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">姓名:</label>
+            <div class="col-xs-12 col-sm-8">
+                  <label class="control-label col-xs-12 col-sm-2" tyle="text-align: left">{$area.name}</label>
+            </div>
+      </div>
+      <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">手机号:</label>
+            <div class="col-xs-12 col-sm-8">
+                  <label class="control-label col-xs-12 col-sm-2" tyle="text-align: left">{$area.phone}</label>
+            </div>
+      </div>
+      <div class="form-group">
+          <label class="control-label col-xs-12 col-sm-2">收货地址:</label>
+          <div class="col-xs-12 col-sm-8">
+              <label class="control-label col-xs-12 col-sm-8" style="text-align: left;">{$area.address}</label>
+          </div>
+      </div>
+  
+      <div class="form-group">
+          <label class="control-label col-xs-12 col-sm-2">物流单号:</label>
+          <div class="col-xs-12 col-sm-8">
+              <input id="c-tracking_no" data-rule="required" class="form-control"  name="row[tracking_no]" type="text" value="{$area.tracking_no|htmlentities}">
+              <input type="hidden" name="row[area_id]" value="{$area.id}"/>
+          </div>
+      </div>
+  
+      <div class="form-group layer-footer">
+          <label class="control-label col-xs-12 col-sm-2"></label>
+          <div class="col-xs-12 col-sm-8">
+              <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+              <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+          </div>
+      </div>
+    </div>
+</form>
+  

+ 0 - 1
application/api/controller/Ledger.php

@@ -105,7 +105,6 @@ class Ledger extends Api
             }
         }
         $res = $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items());
-
         $this->success('',$res);
     }
     /**

+ 12 - 1
application/api/controller/Order.php

@@ -81,7 +81,6 @@ class Order extends Api
         $params = $this->request->post();
         $validate = \think\Loader::validate('Order');
         if(!$validate->scene('pick')->check($params)) $this->error($validate->getError());
-        
         $order_info = $productOrder->where('id', $params['order_id'])->find();
         if(empty($order_info)) $this->error( __("参数有误,无可用产品"));
         $order_data['name']     = $params['name'];
@@ -277,6 +276,18 @@ class Order extends Api
         $this->success('ok');
     }
 
+    //查看快递信息
+    public function getTracking(UserArea $userArea)
+    {
+        $order_id    = $this->request->post('order_id'); // 订单id
+        if(empty($order_id)) throw new Exception(__("参数有误,无可用产品"));
+
+        $tracking_no = $userArea->where('order_id', $order_id)->value('tracking_no');
+        if(empty($tracking_no)) throw new Exception(__("暂无物流信息"));
+
+        $this->success('ok', $tracking_no);
+    }
+
 
     /**
      * 更新订单hash

+ 1 - 0
application/api/controller/Product.php

@@ -70,5 +70,6 @@ class Product extends Api
     }
 
 
+
 }
 

+ 2 - 1
application/api/lang/en/order.php

@@ -15,7 +15,8 @@ return [
       '赠送'                                  => 'Giveaway',
       '关闭'                                  => 'Closure',
       '赠送用户不存在'                         => 'The gift user does not exist',
-      '赠送用户不能是自己'                     => 'The user who sends the gift cannot be yourself' 
+      '赠送用户不能是自己'                     => 'The user who sends the gift cannot be yourself',
+      '暂无物流信息'                           => 'No logistics information',
 
 
 

+ 2 - 1
application/api/lang/zh-cn/order.php

@@ -15,6 +15,7 @@ return [
       '赠送'                  => '赠送',
       '关闭'                  => '关闭',
       '赠送用户不存在'         => '赠送用户不存在',
-      '赠送用户不能是自己'      => '赠送用户不能是自己'
+      '赠送用户不能是自己'      => '赠送用户不能是自己',
+      '暂无物流信息'             => '暂无物流信息',
       
 ];

+ 7 - 0
application/common/model/ProductOrder.php

@@ -74,6 +74,13 @@ class ProductOrder extends Model
         return $this->hasOne('ProductArea', 'id', 'area_id', [], 'LEFT')->setEagerlyType(0);
     }
     
+   
+    //提货地址
+    public function address()
+    {
+        return $this->hasOne('UserArea', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
     public function getCreateTimeTextAttr($value, $data)
     {
         $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');

+ 13 - 2
application/common/model/UserArea.php

@@ -23,9 +23,20 @@ class UserArea  extends Model
     ];
 
 
-     
-
+    const Waiting           = 0;
+    const Shipped           = 1;
+    const Finish            = 2;
+    /* 
+     *  订单状态  0代发货  1已发货 2完成
+     */
+    public $order_status = [
+        '-1'                    => '全部',
+        self::Waiting           => '待发货',
+        self::Shipped           => '已发货',
+        self::Finish            => '完成'
+    ];
 
+    
     public function getCreateTimeTextAttr($value, $data)
     {
         $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');

+ 25 - 3
public/assets/js/backend/offline/order.js

@@ -30,14 +30,32 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'order_id', title: __('Order_id'), operate: false},
                         {field: 'products.zh_name', title: __('Product_id'),operate:'LIKE'},
                         {field: 'areas.address', title: __('Area_id')},
-                        {field: 'type_id', title: __('Type_id'), searchList: {0:__('热销'), 1:__('转让'), 2:__('赠送')}, formatter: Table.api.formatter.status},
+                        {field: 'type_id', title: __('Type_id'), searchList: {0:__('热销'), 1:__('转让'), 2:__('赠送')}, formatter: Table.api.formatter.label},
                         {field: 'from_user', title: __('来源用户Id'), operate:false},
                         {field: 'price', title: __('Price'), operate:false},
                         {field: 'fees', title: __('手续费'), operate:false},
                         {field: 'status', title: __('Status'), searchList: {0:__('已下单'), 1:__('支付'), 2:__('转让'), 3:__('提货'), 4:__('取消'), 5:__('关闭')},formatter: Table.api.formatter.status},
+                        {field: 'address.address', title: __('提货地址'), operate:false},
+                        {field: 'address.status', title: __('发货状态'), searchList: {0:__('待发货'), 1:__('已发货'), 2:__('已完成')}, formatter: Table.api.formatter.flag},
                         {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
-                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
-                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                        {
+                            field: 'operate', title: __('Operate'), table: table,
+                            events: Table.api.events.operate,
+                            buttons: [{
+                                name: 'shipping',
+                                text: '发货',
+                                title: '发货',
+                                classname: 'btn btn-xs btn-primary btn-dialog btn-receivable',
+                                icon: 'fa fa-keyboard-o',
+                                url: 'offline/order/shipping',
+                                //extend: 'data-area=\'["50%", "50%"]\'',
+                                visible: function (row) {
+                                    if(row.status == 3)  return true;
+                                    return false;
+                                }
+                            },],
+                            formatter: Table.api.formatter.operate
+                        }
                     ]
                 ]
             });
@@ -45,6 +63,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 为表格绑定事件
             Table.api.bindevent(table);
         },
+
+        shipping: function () {
+            Controller.api.bindevent();
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));