WaterCardOrder.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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\WaterCardOrder as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterCardOrder 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. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  70. $this->assign(compact('form'));
  71. return $this->fetch('public/form-builder');
  72. }
  73. public function save()
  74. {
  75. $model = new model;
  76. $data = Util::postMore([
  77. 'name',
  78. 'type',
  79. 'th_id',
  80. 'weight',
  81. 'unit_price',
  82. 'company',
  83. 'long',
  84. 'wide',
  85. ]);
  86. $validate = Validate::rule('name', 'require')->rule([
  87. 'name' => 'require',
  88. 'type' => 'require',
  89. 'th_id' => 'require',
  90. 'weight' => 'require',
  91. 'unit_price' => 'require',
  92. 'company' => 'require',
  93. 'long' => 'require',
  94. 'wide' => 'require',
  95. ]);
  96. $validate->message([
  97. 'name.require' => '名称不能为空',
  98. 'type.require' => '请选择分类',
  99. 'th_id.require' => '请选择厚度',
  100. 'weight.require' => '请填写重量',
  101. 'unit_price.require' => '请填写单价',
  102. 'company.require' => '请填写单位',
  103. 'long.require' => '请填写长度',
  104. 'wide.require' => '请填写宽度',
  105. ]);
  106. if (!$validate->check($data)) {
  107. return Json::fail($validate->getError());
  108. }
  109. $res = $model->save($data);
  110. if ($res) return Json::successful('添加成功');
  111. return Json::fail('添加失败');
  112. }
  113. /**
  114. * 显示创建资源表单页.
  115. *
  116. * @return \think\Response
  117. */
  118. public function edit($id = 0)
  119. {
  120. $data = model::find($id);
  121. $f = [];
  122. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  123. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  124. ['value' => 0, 'label' => '请选择分类'],
  125. ['value' => 1, 'label' => '顶板'],
  126. ['value' => 2, 'label' => '侧板'],
  127. ['value' => 3, 'label' => '拉筋'],
  128. ['value' => 4, 'label' => '底板'],
  129. ])->filterable(true);
  130. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  131. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  132. )->filterable(true);
  133. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  134. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  135. $f[] = Form::input('company', '单位', $data['company']);
  136. $f[] = Form::input('long', '长', $data['long']);
  137. $f[] = Form::input('wide', '宽', $data['wide']);
  138. $f[] = Form::hidden('id', $id);
  139. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  140. $this->assign(compact('form'));
  141. return $this->fetch('public/form-builder');
  142. }
  143. /**
  144. * 修改
  145. * @return void
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\DbException
  148. * @throws \think\db\exception\ModelNotFoundException
  149. */
  150. public function update()
  151. {
  152. $model = new model;
  153. $data = Util::postMore([
  154. 'name',
  155. 'type',
  156. 'th_id',
  157. 'weight',
  158. 'unit_price',
  159. 'company',
  160. 'long',
  161. 'wide',
  162. 'id',
  163. ]);
  164. $validate = Validate::rule('name', 'require')->rule([
  165. 'name' => 'require',
  166. 'type' => 'require',
  167. 'th_id' => 'require',
  168. 'weight' => 'require',
  169. 'unit_price' => 'require',
  170. 'company' => 'require',
  171. 'long' => 'require',
  172. 'wide' => 'require',
  173. ]);
  174. $validate->message([
  175. 'name.require' => '名称不能为空',
  176. 'type.require' => '请选择分类',
  177. 'th_id.require' => '请选择厚度',
  178. 'weight.require' => '请填写重量',
  179. 'unit_price.require' => '请填写单价',
  180. 'company.require' => '请填写单位',
  181. 'long.require' => '请填写长度',
  182. 'wide.require' => '请填写宽度',
  183. ]);
  184. $details = $model->find($data['id']);
  185. $details['name'] = $data['name'];
  186. $details['thickness'] = $data['thickness'];
  187. $res = $details->save();
  188. if ($res) return Json::successful('修改成功');
  189. return Json::fail('修改失败');
  190. }
  191. /**
  192. * 删除
  193. * @param $id
  194. * @return void
  195. * @throws \Exception
  196. */
  197. public function delete($id)
  198. {
  199. if (!$id) Json::fail('删除失败');
  200. $model = new model;
  201. $res = model::destroy($id);
  202. if ($res){
  203. return Json::success('删除成功!');
  204. }else{
  205. return Json::fail($model->getErrorInfo());
  206. }
  207. }
  208. }