WaterOrder.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 crmeb\services\{ExpressService,
  10. JsonService,
  11. JsonService as Json,
  12. MiniProgramService,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util};
  17. use think\facade\Route as Url;
  18. use think\facade\Validate;
  19. Use app\admin\model\water\WaterOrder as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterOrder extends AuthController
  26. {
  27. /**
  28. * @return mixed
  29. */
  30. public function index()
  31. {
  32. return $this->fetch();
  33. }
  34. public function list()
  35. {
  36. $where = Util::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ['name', ''],
  40. ['card', ''],
  41. ['order_id', ''],
  42. ]);
  43. return Json::successlayui(model::list($where));
  44. }
  45. /**
  46. * 显示创建资源表单页.
  47. *
  48. * @return \think\Response
  49. */
  50. public function create($id = 0)
  51. {
  52. $f = [];
  53. $f[] = Form::input('name', '名称')->col(12);
  54. $f[] = Form::select('type', '选择分类', '')->options([
  55. ['value' => 0, 'label' => '请选择分类'],
  56. ['value' => 1, 'label' => '顶板'],
  57. ['value' => 2, 'label' => '侧板'],
  58. ['value' => 3, 'label' => '拉筋'],
  59. ['value' => 4, 'label' => '底板'],
  60. ])->filterable(true);
  61. $f[] = Form::select('th_id', '选择厚度', '')->options(
  62. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  63. )->filterable(true);
  64. $f[] = Form::input('weight', '重量(kg)');
  65. $f[] = Form::input('unit_price', '单价');
  66. $f[] = Form::input('company', '单位');
  67. $f[] = Form::input('long', '长');
  68. $f[] = Form::input('wide', '宽');
  69. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  70. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  71. $this->assign(compact('form'));
  72. return $this->fetch('public/form-builder');
  73. }
  74. public function save()
  75. {
  76. $model = new model;
  77. $data = Util::postMore([
  78. 'name',
  79. 'type',
  80. 'th_id',
  81. 'weight',
  82. 'unit_price',
  83. 'company',
  84. 'long',
  85. 'wide',
  86. ]);
  87. $validate = Validate::rule('name', 'require')->rule([
  88. 'name' => 'require',
  89. 'type' => 'require',
  90. 'th_id' => 'require',
  91. 'weight' => 'require',
  92. 'unit_price' => 'require',
  93. 'company' => 'require',
  94. 'long' => 'require',
  95. 'wide' => 'require',
  96. ]);
  97. $validate->message([
  98. 'name.require' => '名称不能为空',
  99. 'type.require' => '请选择分类',
  100. 'th_id.require' => '请选择厚度',
  101. 'weight.require' => '请填写重量',
  102. 'unit_price.require' => '请填写单价',
  103. 'company.require' => '请填写单位',
  104. 'long.require' => '请填写长度',
  105. 'wide.require' => '请填写宽度',
  106. ]);
  107. if (!$validate->check($data)) {
  108. return Json::fail($validate->getError());
  109. }
  110. $res = $model->save($data);
  111. if ($res) return Json::successful('添加成功');
  112. return Json::fail('添加失败');
  113. }
  114. /**
  115. * 显示创建资源表单页.
  116. *
  117. * @return \think\Response
  118. */
  119. public function edit($id = 0)
  120. {
  121. $data = model::find($id);
  122. $f = [];
  123. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  124. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  125. ['value' => 0, 'label' => '请选择分类'],
  126. ['value' => 1, 'label' => '顶板'],
  127. ['value' => 2, 'label' => '侧板'],
  128. ['value' => 3, 'label' => '拉筋'],
  129. ['value' => 4, 'label' => '底板'],
  130. ])->filterable(true);
  131. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  132. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  133. )->filterable(true);
  134. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  135. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  136. $f[] = Form::input('company', '单位', $data['company']);
  137. $f[] = Form::input('long', '长', $data['long']);
  138. $f[] = Form::input('wide', '宽', $data['wide']);
  139. $f[] = Form::hidden('id', $id);
  140. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  141. $this->assign(compact('form'));
  142. return $this->fetch('public/form-builder');
  143. }
  144. /**
  145. * 修改
  146. * @return void
  147. * @throws \think\db\exception\DataNotFoundException
  148. * @throws \think\db\exception\DbException
  149. * @throws \think\db\exception\ModelNotFoundException
  150. */
  151. public function update()
  152. {
  153. $model = new model;
  154. $data = Util::postMore([
  155. 'name',
  156. 'type',
  157. 'th_id',
  158. 'weight',
  159. 'unit_price',
  160. 'company',
  161. 'long',
  162. 'wide',
  163. 'id',
  164. ]);
  165. $validate = Validate::rule('name', 'require')->rule([
  166. 'name' => 'require',
  167. 'type' => 'require',
  168. 'th_id' => 'require',
  169. 'weight' => 'require',
  170. 'unit_price' => 'require',
  171. 'company' => 'require',
  172. 'long' => 'require',
  173. 'wide' => 'require',
  174. ]);
  175. $validate->message([
  176. 'name.require' => '名称不能为空',
  177. 'type.require' => '请选择分类',
  178. 'th_id.require' => '请选择厚度',
  179. 'weight.require' => '请填写重量',
  180. 'unit_price.require' => '请填写单价',
  181. 'company.require' => '请填写单位',
  182. 'long.require' => '请填写长度',
  183. 'wide.require' => '请填写宽度',
  184. ]);
  185. $details = $model->find($data['id']);
  186. $details['name'] = $data['name'];
  187. $details['thickness'] = $data['thickness'];
  188. $res = $details->save();
  189. if ($res) return Json::successful('修改成功');
  190. return Json::fail('修改失败');
  191. }
  192. /**
  193. * 删除
  194. * @param $id
  195. * @return void
  196. * @throws \Exception
  197. */
  198. public function delete($id)
  199. {
  200. if (!$id) Json::fail('删除失败');
  201. $model = new model;
  202. $res = model::destroy($id);
  203. if ($res){
  204. return Json::success('删除成功!');
  205. }else{
  206. return Json::fail($model->getErrorInfo());
  207. }
  208. }
  209. }