ServeMealRepository.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\system\serve;
  12. use app\common\dao\system\serve\ServeMealDao;
  13. use app\common\repositories\BaseRepository;
  14. use FormBuilder\Factory\Elm;
  15. use think\exception\ValidateException;
  16. use think\facade\Route;
  17. class ServeMealRepository extends BaseRepository
  18. {
  19. protected $dao;
  20. public function __construct(ServeMealDao $dao)
  21. {
  22. $this->dao = $dao;
  23. }
  24. public function getList(array $where, int $page, int $limit)
  25. {
  26. $where['is_del'] = 0;
  27. $query = $this->dao->getSearch($where)->order('create_time DESC');
  28. $count = $query->count();
  29. $list = $query->page($page, $limit)->select();
  30. return compact('count','list');
  31. }
  32. public function updateForm($id)
  33. {
  34. $data = $this->dao->get($id);
  35. if(!$data) throw new ValidateException('数据不存在');
  36. $data = $data->toArray();
  37. return $this->form($id,$data);
  38. }
  39. public function form($id = null, array $formData = [])
  40. {
  41. $isCreate = is_null($id);
  42. $action = Route::buildUrl($isCreate ? 'systemServeMealCreate' : 'systemServeMealUpdate', $isCreate ? [] : compact('id'))->build();
  43. return Elm::createForm($action, [
  44. Elm::input('name', '套餐名称')->required(),
  45. Elm::radio('type', '套餐类型 ',1)->options([
  46. ['value' => 1, 'label' => '一号通商品采集'],
  47. ['value' => 2, 'label' => '一号通电子面单'],
  48. ]),
  49. Elm::number('price', '价格')->required(),
  50. Elm::number('num', '数量')->required(),
  51. Elm::radio('status', '状态', 1)->options([
  52. ['label' => '开启', 'value' => 1],
  53. ['label' => '关闭', 'value' => 0]
  54. ]),
  55. Elm::number('sort', '排序')->required()->precision(0)->max(99999),
  56. ])->setTitle($isCreate ? '添加套餐' : '编辑套餐')->formData($formData);
  57. }
  58. public function delete($id)
  59. {
  60. $data = $this->dao->get($id);
  61. if(!$data) throw new ValidateException('数据不存在');
  62. $data->is_del = 1;
  63. $data->save();
  64. }
  65. public function QrCode(int $merId, array $data)
  66. {
  67. $ret = $this->dao->get($data['meal_id']);
  68. if(!$data) throw new ValidateException('数据不存在');
  69. $param = [
  70. 'status' => 0,
  71. 'is_del' => 0,
  72. 'mer_id' => $merId,
  73. 'type' => $data['type'],
  74. 'meal_id'=> $ret['meal_id'],
  75. ];
  76. $this->dao->getSearch($param)->finid();
  77. }
  78. public function setOrderSn()
  79. {
  80. list($msec, $sec) = explode(' ', microtime());
  81. $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
  82. $orderId = 'cs' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
  83. return $orderId;
  84. }
  85. }