123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\controller\water;
- use app\admin\controller\AuthController;
- use app\admin\model\user\User;
- use app\admin\model\water\WaterMaterial;
- use crmeb\services\{ExpressService,
- JsonService,
- JsonService as Json,
- MiniProgramService,
- PHPExcelService,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util};
- use think\facade\Route as Url;
- use think\facade\Validate;
- Use app\admin\model\water\WaterQuery as model;
- /**
- * 订单管理控制器 同一个订单表放在一个控制器
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class WaterQuery extends AuthController
- {
- /**
- * @return mixed
- */
- public function index($uid = 0)
- {
- $this->assign('uid', $uid);
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['name', ''],
- ['card', ''],
- ['order_id', ''],
- ['uid', ''],
- ['excel', 0],
- ]);
- return Json::successlayui(model::list($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $f = [];
- $f[] = Form::number('water_mouth', '水口价格');
- $f[] = Form::number('partition', '隔板价格');
- $f[] = Form::number('tax_point', '税点(百分比)');
- $f[] = Form::textarea('remarks', '备注');
- $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function save()
- {
- $model = new model;
- $data = Util::postMore([
- 'water_mouth',
- 'partition',
- 'tax_point',
- 'id',
- 'remarks',
- ]);
- $validate = Validate::rule([
- 'water_mouth' => 'require',
- 'partition' => 'require',
- 'tax_point' => 'require',
- ]);
- $validate->message([
- 'water_mouth.require' => '输入水口价格',
- 'partition.require' => '隔板价格',
- 'tax_point.require' => '输入税点',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $query = model::where('id', $data['id'])->find();
- if (!$query) return Json::fail('查询订单不存在');
- $money = $query['price'] + $data['water_mouth'] + $data['partition'];
- $res = \app\admin\model\water\WaterOrder::create([
- 'uid' => $query['uid'],
- 'query_id' => $query['id'],
- 'order_id' => $this->getNewOrderId(),
- 'long' => $query['long'],
- 'wide' => $query['wide'],
- 'high' => $query['high'],
- 'is_warm' => $query['is_warm'],
- 'is_channel' => $query['is_channel'],
- 'is_ladder' => $query['is_ladder'],
- 'is_gc' => $query['is_gc'],
- 'water_mouth' => $data['water_mouth'],
- 'partition' => $data['partition'],
- 'tax_point' => $data['tax_point'],
- 'tax' => $money * ($data['tax_point']/100),
- 'price' => $money,
- 'weight' => $query['weight'],
- 'remarks' => $data['remarks'],
- ]);
- if ($res) return Json::successful('转为订单成功');
- return Json::fail('添加失败');
- }
- /**
- * 生成订单唯一id
- * @param $uid 用户uid
- * @return string
- */
- public function getNewOrderId()
- {
- do {
- list($msec, $sec) = explode(' ', microtime());
- $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
- $orderId = 'w' . $msectime . mt_rand(10000, 99999);
- } while (\app\admin\model\water\WaterOrder::be(['order_id' => $orderId]));// $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
- return $orderId;
- }
- /**
- * 详情
- * @param $id
- * @return string
- * @throws \Exception
- */
- public function details($id)
- {
- $model = new WaterMaterial();
- $model = $model->where('query_id', $id);
- // $model = $model->order('id desc');
- $this->assign( WaterMaterial::page($model, null, null, '100'));
- return $this->fetch();
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $model = new model;
- $res = model::destroy($id);
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail($model->getErrorInfo());
- }
- }
- public function excel($id)
- {
- $details = \app\admin\model\water\WaterQuery::where('id', $id)->find();
- $list = WaterMaterial::where('query_id', $id)->select();
- $user = User::where('uid', $details['uid'])->find();
- $export = [];
- foreach ($list as $item)
- {
- $export[] = [
- $item['title'],
- $item['name'],
- $item['code'],
- $item['specifications'],
- $item['number'],
- $item['unit_price'],
- $item['ot_price'],
- $item['weight'],
- $item['company'],
- $item['create_time'],
- ];
- }
- PHPExcelService::setExcelHeader(['标题', '名称','编号', '规格', '数量', '单价', '总价', '重量','单位','时间'])
- ->setExcelTile('用户'.$user['phone'].'计算记录导出', '计算信息' . time(), '记录ID'.$details['id'].'-总价'.$details['price'])
- ->setExcelContent($export)
- ->ExcelSave();
- }
- }
|