Verify.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\cashier\storeapi\controller;
  13. use app\model\verify\Verify as VerifyModel;
  14. use app\model\verify\VerifyRecord;
  15. use app\storeapi\controller\BaseStoreApi;
  16. /**
  17. * 订单核销控制器
  18. * Class Verify
  19. * @package addon\shop\siteapi\controller
  20. */
  21. class Verify extends BaseStoreApi
  22. {
  23. /**
  24. * 获取核销码信息
  25. * @return false|string
  26. */
  27. public function info()
  28. {
  29. $code = $this->params[ 'code' ] ?? '';
  30. $verify_model = new VerifyModel();
  31. $condition = [
  32. [ 'verify_code', '=', $code ],
  33. [ 'site_id', '=', $this->site_id ],
  34. [ 'store_id', 'in', [0, $this->store_id] ]
  35. ];
  36. $info = $verify_model->getVerifyInfo($condition);
  37. return $this->response($info);
  38. }
  39. /**
  40. * 核销类型
  41. */
  42. public function verifyType()
  43. {
  44. $verify_model = new VerifyModel();
  45. $verify_type = $verify_model->getVerifyType();
  46. return $this->response($this->success($verify_type));
  47. }
  48. /**
  49. * 核销
  50. */
  51. public function verify()
  52. {
  53. $verify_code = $this->params[ 'verify_code' ] ?? '';
  54. $info = array (
  55. "verifier_id" => $this->uid,
  56. "verifier_name" => $this->user_info[ 'username' ],
  57. "verify_from" => 'shop',
  58. "store_id" => $this->store_id
  59. );
  60. $verify_model = new VerifyModel();
  61. $res = $verify_model->verify($info, $verify_code);
  62. return $this->response($res);
  63. }
  64. /**
  65. * 核销记录
  66. * @return mixed
  67. */
  68. public function recordLists()
  69. {
  70. $verify_model = new VerifyRecord();
  71. $page = $this->params[ 'page' ] ?? 1;
  72. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  73. $verify_type = $this->params[ 'verify_type' ] ?? '';//验证类型
  74. $search_text = $this->params[ 'search_text' ] ?? '';
  75. $start_time = $this->params[ 'start_time' ] ?? '';
  76. $end_time = $this->params[ 'end_time' ] ?? '';
  77. $condition = [
  78. [ 'store_id', '=', $this->store_id ],
  79. ];
  80. if (!empty($search_text)) {
  81. $condition[] = [ 'verify_code|verifier_name', 'like', '%' . $search_text . '%' ];
  82. }
  83. if (!empty($start_time) && empty($end_time)) {
  84. $condition[] = [ 'verify_time', '>=', date_to_time($start_time) ];
  85. } elseif (empty($start_time) && !empty($end_time)) {
  86. $condition[] = [ 'verify_time', '<=', date_to_time($end_time) ];
  87. } elseif (!empty($start_time) && !empty($end_time)) {
  88. $condition[] = [ 'verify_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  89. }
  90. $list = $verify_model->getVerifyRecordsPageList($condition, $page, $page_size, '*', 'verify_time desc');
  91. return $this->response($list);
  92. }
  93. /**
  94. * 核销记录详情
  95. * @return false|string
  96. */
  97. public function recordsDetail()
  98. {
  99. $id = $this->params[ 'id' ] ?? 0;
  100. $verify_model = new VerifyRecord();
  101. $condition = [
  102. [ 'vr.id', '=', $id ],
  103. [ 'vr.store_id', '=', $this->store_id ]
  104. ];
  105. $field = 'vr.*,v.verify_type_name,v.expire_time,v.verify_total_count,v.verify_use_num,v.verify_content_json,v.member_id, m.nickname,m.headimg,m.mobile';
  106. $join = [
  107. [ 'verify v', 'v.verify_code = vr.verify_code', 'left' ],
  108. [ 'member m', 'v.member_id = m.member_id', 'left' ],
  109. ];
  110. $verify_detail = $verify_model->getVerifyRecordsInfo($condition, $field, 'vr', $join)[ 'data' ] ?? [];
  111. if (!empty($verify_detail)) {
  112. $verify_detail['verify_content_json'] = json_decode($verify_detail['verify_content_json'], true);
  113. }
  114. return $this->response($this->success($verify_detail));
  115. }
  116. }