作者 李忠强

更新

  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +
  7 +/**
  8 + * 运费规则
  9 + *
  10 + * @icon fa fa-circle-o
  11 + */
  12 +class LitestoreRiderRule extends Backend
  13 +{
  14 +
  15 + /**
  16 + * LitestoreRiderRule模型对象
  17 + * @var \app\admin\model\LitestoreRiderRule
  18 + */
  19 + protected $model = null;
  20 +
  21 + public function _initialize()
  22 + {
  23 + parent::_initialize();
  24 + $this->model = new \app\admin\model\LitestoreRiderRule;
  25 +
  26 + }
  27 +
  28 + public function import()
  29 + {
  30 + parent::import();
  31 + }
  32 +
  33 + /**
  34 + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  35 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  36 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  37 + */
  38 +
  39 +
  40 +}
@@ -14,7 +14,7 @@ class Litestorefreight extends Backend @@ -14,7 +14,7 @@ class Litestorefreight extends Backend
14 14
15 /** 15 /**
16 * Litestore_freight模型对象 16 * Litestore_freight模型对象
17 - * @var \app\admin\model\Litestorefreight 17 + * @var \app\admin\model\litestore\Litestorefreight
18 */ 18 */
19 protected $model = null; 19 protected $model = null;
20 20
  1 +<?php
  2 +
  3 +return [
  4 + 'First' => '首公里',
  5 + 'First_fee' => '运费(元)',
  6 + 'Additional' => '续公里',
  7 + 'Additional_fee' => '运费(元)'
  8 +];
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +
  8 +class LitestoreRiderRule extends Model
  9 +{
  10 +
  11 +
  12 +
  13 +
  14 +
  15 + // 表名
  16 + protected $name = 'litestore_rider_rule';
  17 +
  18 + // 自动写入时间戳字段
  19 + protected $autoWriteTimestamp = false;
  20 +
  21 + // 定义时间戳字段名
  22 + protected $createTime = false;
  23 + protected $updateTime = false;
  24 + protected $deleteTime = false;
  25 +
  26 + // 追加属性
  27 + protected $append = [
  28 + 'create_time_text'
  29 + ];
  30 +
  31 +
  32 +
  33 +
  34 +
  35 +
  36 + public function getCreateTimeTextAttr($value, $data)
  37 + {
  38 + $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  39 + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40 + }
  41 +
  42 + protected function setCreateTimeAttr($value)
  43 + {
  44 + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  45 + }
  46 +
  47 +
  48 +}
  1 +<?php
  2 +
  3 +namespace app\admin\validate;
  4 +
  5 +use think\Validate;
  6 +
  7 +class LitestoreRiderRule extends Validate
  8 +{
  9 + /**
  10 + * 验证规则
  11 + */
  12 + protected $rule = [
  13 + ];
  14 + /**
  15 + * 提示消息
  16 + */
  17 + protected $message = [
  18 + ];
  19 + /**
  20 + * 验证场景
  21 + */
  22 + protected $scene = [
  23 + 'add' => [],
  24 + 'edit' => [],
  25 + ];
  26 +
  27 +}
  1 +<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('First')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-first" data-rule="required" min="0" class="form-control" name="row[first]" type="number" value="0">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('First_fee')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-first_fee" data-rule="required" min="0" class="form-control" step="0.01" name="row[first_fee]" type="number" value="0.00">
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label class="control-label col-xs-12 col-sm-2">{:__('Additional')}:</label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <input id="c-additional" data-rule="required" min="0" class="form-control" name="row[additional]" type="number" value="0">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label class="control-label col-xs-12 col-sm-2">{:__('Additional_fee')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <input id="c-additional_fee" data-rule="required" min="0" class="form-control" step="0.01" name="row[additional_fee]" type="number" value="0.00">
  25 + </div>
  26 + </div>
  27 + <div class="form-group">
  28 + <label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label>
  29 + <div class="col-xs-12 col-sm-8">
  30 + <input id="c-create_time" data-rule="required" min="0" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:date('Y-m-d H:i:s')}">
  31 + </div>
  32 + </div>
  33 + <div class="form-group layer-footer">
  34 + <label class="control-label col-xs-12 col-sm-2"></label>
  35 + <div class="col-xs-12 col-sm-8">
  36 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  37 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  38 + </div>
  39 + </div>
  40 +</form>
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('First')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-first" data-rule="required" min="0" class="form-control" name="row[first]" type="number" value="{$row.first|htmlentities}">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('First_fee')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-first_fee" data-rule="required" min="0" class="form-control" step="0.01" name="row[first_fee]" type="number" value="{$row.first_fee|htmlentities}">
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label class="control-label col-xs-12 col-sm-2">{:__('Additional')}:</label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <input id="c-additional" data-rule="required" min="0" class="form-control" name="row[additional]" type="number" value="{$row.additional|htmlentities}">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label class="control-label col-xs-12 col-sm-2">{:__('Additional_fee')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <input id="c-additional_fee" data-rule="required" min="0" class="form-control" step="0.01" name="row[additional_fee]" type="number" value="{$row.additional_fee|htmlentities}">
  25 + </div>
  26 + </div>
  27 + <div class="form-group layer-footer">
  28 + <label class="control-label col-xs-12 col-sm-2"></label>
  29 + <div class="col-xs-12 col-sm-8">
  30 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  31 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  32 + </div>
  33 + </div>
  34 +</form>
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 +
  4 + <div class="panel-body">
  5 + <div id="myTabContent" class="tab-content">
  6 + <div class="tab-pane fade active in" id="one">
  7 + <div class="widget-body no-padding">
  8 + <div id="toolbar" class="toolbar">
  9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 +<!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('litestore_rider_rule/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
  11 + <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('litestore_rider_rule/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
  12 +<!-- <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('litestore_rider_rule/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
  13 +<!-- <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('litestore_rider_rule/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
  14 +
  15 +<!-- <div class="dropdown btn-group {:$auth->check('litestore_rider_rule/multi')?'':'hide'}">-->
  16 +<!-- <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
  17 +<!-- <ul class="dropdown-menu text-left" role="menu">-->
  18 +<!-- <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->
  19 +<!-- <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->
  20 +<!-- </ul>-->
  21 +<!-- </div>-->
  22 +
  23 +
  24 + </div>
  25 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  26 + data-operate-edit="{:$auth->check('litestore_rider_rule/edit')}"
  27 + data-operate-del="{:$auth->check('litestore_rider_rule/del')}"
  28 + width="100%">
  29 + </table>
  30 + </div>
  31 + </div>
  32 +
  33 + </div>
  34 + </div>
  35 +</div>
@@ -6,6 +6,7 @@ namespace app\api\controller; @@ -6,6 +6,7 @@ namespace app\api\controller;
6 6
7 use app\api\model\GoodsSpec; 7 use app\api\model\GoodsSpec;
8 use app\api\model\SpecValue; 8 use app\api\model\SpecValue;
  9 +use app\api\model\UserCoupon;
9 use app\common\controller\Api; 10 use app\common\controller\Api;
10 use think\Db; 11 use think\Db;
11 use think\exception\PDOException; 12 use think\exception\PDOException;
@@ -207,6 +208,62 @@ class Order extends Api @@ -207,6 +208,62 @@ class Order extends Api
207 $this->success('下单页详情',['list'=>$goods_array,'price'=>$sum_price]); 208 $this->success('下单页详情',['list'=>$goods_array,'price'=>$sum_price]);
208 } 209 }
209 210
  211 + /**
  212 + * @ApiTitle (计算运费)
  213 + * @ApiMethod (POST)
  214 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  215 + * @ApiParams (name="address_id", type="integer", required=true, description="地址id")
  216 + * @ApiReturn ({
  217 + 'code':'1',
  218 + 'msg':'返回成功'
  219 + 'data':
  220 + "price": "37574.00" 总价
  221 + })
  222 + */
  223 + public function freightCalculation()
  224 + {
  225 + $address_id = $this->request->post('address_id');
  226 + if (!$address_id) $this->error('请选择地址');
  227 +
  228 + $this->success('下单页详情',['price'=>$sum_price]);
  229 + }
  230 +
  231 + /**
  232 + * @ApiTitle (选择优惠券)
  233 + * @ApiMethod (POST)
  234 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  235 + * @ApiParams (name="price", type="float", required=true, description="订单价格")
  236 + * @ApiReturn ({
  237 + 'code':'1',
  238 + 'msg':'返回成功'
  239 + "data": [
  240 + {
  241 + "id": 1,
  242 + "user_id": 1,
  243 + "coupon_id": 1,
  244 + "name": "手动阀手动阀",
  245 + "price": "1.00", 优惠券金额
  246 + "full_price": "10.00", 满减金额
  247 + "createtime": 111122244,
  248 + "endtime": 1641869388,
  249 + "status": "0",
  250 + "endtime_text": "2022年01月11日到期"
  251 + }
  252 + ]
  253 + })
  254 + */
  255 + public function chooseCoupon()
  256 + {
  257 + $price = $this->request->post('price');
  258 + if (!is_numeric($price)) $this->error('订单价格不合法');
  259 + $model = new UserCoupon();
  260 + $list = $model
  261 + ->where('status','0')
  262 + ->where('user_id',$this->auth->id)
  263 + ->where('full_price','<',$price)
  264 + ->select();
  265 + $this->success('用户优惠券列表',$list);
  266 + }
210 267
211 /** 268 /**
212 * @ApiTitle (下单) 269 * @ApiTitle (下单)
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\controller;
  5 +
  6 +
  7 +use app\api\model\RiderOrder;
  8 +use app\common\controller\Api;
  9 +
  10 +class Rider extends Api
  11 +{
  12 + protected $noNeedRight = ['*'];
  13 + protected $noNeedLogin = ['*'];
  14 +
  15 + /**
  16 + * @ApiTitle (骑手订单页)
  17 + * @ApiMethod (POST)
  18 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  19 + * @ApiParams (name=page, type=integer, required=true, description="页数")
  20 + * @ApiParams (name=lat, type=integer, required=true, description="骑手纬度")
  21 + * @ApiParams (name=lng, type=integer, required=true, description="骑手经度")
  22 + * @ApiReturn ({
  23 + 'code':'1',
  24 + 'msg':'返回成功'
  25 + 'data':
  26 + "total": 2,
  27 + "per_page": 5,
  28 + "current_page": 1,
  29 + "last_page": 1,
  30 + "data": [
  31 + {
  32 + "id": 1,
  33 + "distance": 111.263, 距离
  34 + "address": {
  35 + "name": "1", 收件人
  36 + "phone": "13549059988", 电话号码
  37 + "detail": "阿松大", 地址
  38 + "address": "阿松大", 门牌号
  39 + },
  40 + "orderdetail": {
  41 + "order_no": "LQ-16420622494781", 订单编号
  42 + "createtime_text": ""
  43 + }
  44 + }
  45 + ]
  46 + })
  47 + */
  48 + public function index()
  49 + {
  50 + $page = $this->request->post('page',1);
  51 + $lat = $this->request->post('lat');
  52 + $lng = $this->request->post('lng');
  53 + if (!is_numeric($page)) $this->error('页数不合法');
  54 + if (!is_numeric($lat)) $this->error('纬度不合法');
  55 + if (!is_numeric($lng)) $this->error('经度不合法');
  56 + $model = new RiderOrder();
  57 + $EARTH=6378.137; //地球半径
  58 + $PI=3.14; //PI值 圆周率
  59 + $list = $model
  60 + ->with(['address','orderdetail'])
  61 + ->where('fa_rider_order.user_id',$this->auth->id)
  62 + ->where('fa_rider_order.status','1')
  63 + ->field('Round((2 * '.$EARTH.'* ASIN(SQRT(POW(SIN('.$PI.'*('.$lat.'-lat)/360),2)
  64 + +COS('.$PI.'*'.$lat.'/180)* COS(lat * '.$PI.'/180)
  65 + *POW(SIN('.$PI.'*('.$lng.'-lng)/360),2)))),3) as distance')
  66 + ->order('distance')
  67 + ->paginate(5,false,['page'=>$page])
  68 + ->each(function ($item,$key){
  69 + $item->getRelation('orderdetail')->visible(['order_no']);
  70 + $item->getRelation('address')->visible(['name','phone','address','detail']);
  71 + $item->visible(['orderdetail','address','distance','id']);
  72 + });
  73 + $this->success('订单列表',$list);
  74 + }
  75 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\api\model;
  5 +
  6 +
  7 +use think\Model;
  8 +
  9 +class RiderOrder extends Model
  10 +{
  11 + protected $createTime = 'createtime';
  12 + protected $updateTime = '';
  13 +
  14 + public function address()
  15 + {
  16 + return $this->belongsTo('OrderAddress','address_id','id')->setEagerlyType(0);
  17 + }
  18 +
  19 + public function orderdetail()
  20 + {
  21 + return $this->belongsTo('Order','order_id','id');
  22 + }
  23 +}
  1 +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2 +
  3 + var Controller = {
  4 + index: function () {
  5 + // 初始化表格参数配置
  6 + Table.api.init({
  7 + extend: {
  8 + index_url: 'litestore_rider_rule/index' + location.search,
  9 + add_url: 'litestore_rider_rule/add',
  10 + edit_url: 'litestore_rider_rule/edit',
  11 + del_url: 'litestore_rider_rule/del',
  12 + multi_url: 'litestore_rider_rule/multi',
  13 + import_url: 'litestore_rider_rule/import',
  14 + table: 'litestore_rider_rule',
  15 + }
  16 + });
  17 +
  18 + var table = $("#table");
  19 +
  20 + // 初始化表格
  21 + table.bootstrapTable({
  22 + url: $.fn.bootstrapTable.defaults.extend.index_url,
  23 + pk: 'id',
  24 + sortName: 'id',
  25 + search:false,
  26 + showSearch:false,
  27 + showExport:false,
  28 + columns: [
  29 + [
  30 + {checkbox: true},
  31 + {field: 'id', title: __('Id')},
  32 + {field: 'first', title: __('First'), operate:'BETWEEN'},
  33 + {field: 'first_fee', title: __('First_fee'), operate:'BETWEEN'},
  34 + {field: 'additional', title: __('Additional'), operate:'BETWEEN'},
  35 + {field: 'additional_fee', title: __('Additional_fee'), operate:'BETWEEN'},
  36 + // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  37 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  38 + ]
  39 + ]
  40 + });
  41 +
  42 + // 为表格绑定事件
  43 + Table.api.bindevent(table);
  44 + },
  45 + add: function () {
  46 + Controller.api.bindevent();
  47 + },
  48 + edit: function () {
  49 + Controller.api.bindevent();
  50 + },
  51 + api: {
  52 + bindevent: function () {
  53 + Form.api.bindevent($("form[role=form]"));
  54 + }
  55 + }
  56 + };
  57 + return Controller;
  58 +});