WaterQuery.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\water;
  8. use app\admin\controller\AuthController;
  9. use app\admin\model\water\WaterMaterial;
  10. use crmeb\services\{ExpressService,
  11. JsonService,
  12. JsonService as Json,
  13. MiniProgramService,
  14. WechatService,
  15. FormBuilder as Form,
  16. CacheService,
  17. UtilService as Util};
  18. use think\facade\Route as Url;
  19. use think\facade\Validate;
  20. Use app\admin\model\water\WaterQuery as model;
  21. /**
  22. * 订单管理控制器 同一个订单表放在一个控制器
  23. * Class StoreOrder
  24. * @package app\admin\controller\store
  25. */
  26. class WaterQuery extends AuthController
  27. {
  28. /**
  29. * @return mixed
  30. */
  31. public function index()
  32. {
  33. return $this->fetch();
  34. }
  35. public function list()
  36. {
  37. $where = Util::getMore([
  38. ['page', 1],
  39. ['limit', 20],
  40. ['name', ''],
  41. ['card', ''],
  42. ['order_id', ''],
  43. ]);
  44. return Json::successlayui(model::list($where));
  45. }
  46. /**
  47. * 显示创建资源表单页.
  48. *
  49. * @return \think\Response
  50. */
  51. public function create($id = 0)
  52. {
  53. $f = [];
  54. $f[] = Form::number('water_mouth', '水口价格');
  55. $f[] = Form::number('partition', '隔板价格');
  56. $f[] = Form::number('tax_point', '税点(百分比)');
  57. $f[] = Form::hidden('id', $id);
  58. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  59. $this->assign(compact('form'));
  60. return $this->fetch('public/form-builder');
  61. }
  62. public function save()
  63. {
  64. $model = new model;
  65. $data = Util::postMore([
  66. 'water_mouth',
  67. 'partition',
  68. 'tax_point',
  69. 'id',
  70. ]);
  71. $validate = Validate::rule([
  72. 'water_mouth' => 'require',
  73. 'partition' => 'require',
  74. 'tax_point' => 'require',
  75. ]);
  76. $validate->message([
  77. 'water_mouth.require' => '输入水口价格',
  78. 'partition.require' => '隔板价格',
  79. 'tax_point.require' => '输入税点',
  80. ]);
  81. if (!$validate->check($data)) {
  82. return Json::fail($validate->getError());
  83. }
  84. $query = model::where('id', $data['id'])->find();
  85. if (!$query) return Json::fail('查询订单不存在');
  86. $money = $query['price'] + $data['water_mouth'] + $data['partition'];
  87. $res = \app\admin\model\water\WaterOrder::create([
  88. 'uid' => $query['uid'],
  89. 'query_id' => $query['id'],
  90. 'order_id' => $this->getNewOrderId(),
  91. 'long' => $query['long'],
  92. 'wide' => $query['wide'],
  93. 'high' => $query['high'],
  94. 'is_warm' => $query['is_warm'],
  95. 'is_channel' => $query['is_channel'],
  96. 'is_ladder' => $query['is_ladder'],
  97. 'is_gc' => $query['is_gc'],
  98. 'water_mouth' => $data['water_mouth'],
  99. 'partition' => $data['partition'],
  100. 'tax_point' => $data['tax_point'],
  101. 'tax' => $money * ($data['tax_point']/100),
  102. 'price' => $money,
  103. 'weight' => $query['weight'],
  104. ]);
  105. if ($res) return Json::successful('转为订单成功');
  106. return Json::fail('添加失败');
  107. }
  108. /**
  109. * 生成订单唯一id
  110. * @param $uid 用户uid
  111. * @return string
  112. */
  113. public function getNewOrderId()
  114. {
  115. do {
  116. list($msec, $sec) = explode(' ', microtime());
  117. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  118. $orderId = 'w' . $msectime . mt_rand(10000, 99999);
  119. } while (\app\admin\model\water\WaterOrder::be(['order_id' => $orderId]));// $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
  120. return $orderId;
  121. }
  122. /**
  123. * 详情
  124. * @param $id
  125. * @return string
  126. * @throws \Exception
  127. */
  128. public function details($id)
  129. {
  130. $model = new WaterMaterial();
  131. $model = $model->where('query_id', $id);
  132. // $model = $model->order('id desc');
  133. $this->assign( WaterMaterial::page($model, null, null, '100'));
  134. return $this->fetch();
  135. }
  136. /**
  137. * 删除
  138. * @param $id
  139. * @return void
  140. * @throws \Exception
  141. */
  142. public function delete($id)
  143. {
  144. if (!$id) Json::fail('删除失败');
  145. $model = new model;
  146. $res = model::destroy($id);
  147. if ($res){
  148. return Json::success('删除成功!');
  149. }else{
  150. return Json::fail($model->getErrorInfo());
  151. }
  152. }
  153. }