TableQrcodeServices.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\activity\table;
  13. use app\services\BaseServices;
  14. use app\dao\activity\table\TableQrcodeDao;
  15. use app\services\other\QrcodeServices;
  16. use think\exception\ValidateException;
  17. /**
  18. *
  19. * Class TableQrcodeServices
  20. * @package app\services\activity\table
  21. * @mixin TableQrcodeDao
  22. */
  23. class TableQrcodeServices extends BaseServices
  24. {
  25. /**
  26. * TableQrcodeServices constructor.
  27. * @param TableQrcodeDao $dao
  28. */
  29. public function __construct(TableQrcodeDao $dao)
  30. {
  31. $this->dao = $dao;
  32. }
  33. /**桌码列表
  34. * @param array $where
  35. * @param int $storeId
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function tableQrcodeyList(array $where, int $storeId)
  42. {
  43. [$page, $limit] = $this->getPageValue();
  44. $where['store_id'] = $storeId;
  45. $where['is_del'] = 0;
  46. $list = $this->dao->getList($where, $page, $limit, ['category']);
  47. foreach ($list as $key => &$item) {
  48. if (!$item['qrcode']) {
  49. $item['qrcode'] = $this->setQrcodey((int)$item['id'], (int)$item['store_id'], (int)$item['table_number']);
  50. }
  51. }
  52. $count = $this->dao->count($where);
  53. return compact('list', 'count');
  54. }
  55. /**生成桌码
  56. * @param int $id
  57. * @param int $store_id
  58. * @param int $table_number
  59. * @return bool|string
  60. */
  61. public function setQrcodey(int $id, int $store_id, int $table_number)
  62. {
  63. /** @var QrcodeServices $qrcodeServices */
  64. $qrcodeServices = app()->make(QrcodeServices::class);
  65. $parame['store_id'] = $store_id;
  66. $parame['table_number'] = $table_number;
  67. $qrcode = $qrcodeServices->getRoutineQrcodePath($id, 0, 9, $parame);
  68. $this->dao->update($id, ['qrcode' => $qrcode]);
  69. return $qrcode;
  70. }
  71. /**获取桌码信息
  72. * @param int $id
  73. * @param array $with
  74. * @return array
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. */
  79. public function getQrcodeyInfo(int $id, array $with = [])
  80. {
  81. $Info = $this->dao->getTableCodeOne(['id' => $id, 'is_using' => 1], $with);
  82. if (!$Info) {
  83. throw new ValidateException('获取信息失败');
  84. }
  85. return $Info->toArray();
  86. }
  87. }