Freeshipping.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\freeshipping\model;
  11. use app\model\BaseModel;
  12. class Freeshipping extends BaseModel
  13. {
  14. /**
  15. * 添加满额包邮
  16. * @param $data
  17. * @return array
  18. */
  19. public function addFreeshipping($data)
  20. {
  21. $data[ 'create_time' ] = time();
  22. $area_ids = json_decode($data[ 'area_ids' ], true);
  23. if (!empty($area_ids)) {
  24. foreach ($area_ids[ '3' ] as $k => $v) {
  25. if (!empty($area_ids[ '3' ])) {
  26. foreach ($v as $area_id) {
  27. //判断该城市是否已存在
  28. $count = model('promotion_freeshipping')->getCount(
  29. [
  30. [ 'site_id', '=', $data[ 'site_id' ] ],
  31. [ 'area_ids', 'like', '%' . $area_id . '%' ],
  32. ]
  33. );
  34. if ($count > 0) {
  35. return $this->error('', '指定地区城市不能重复');
  36. }
  37. }
  38. }
  39. }
  40. }
  41. $res = model('promotion_freeshipping')->add($data);
  42. return $this->success($res);
  43. }
  44. /**
  45. * 编辑满额包邮
  46. * @param $groupbuy_id
  47. * @param $site_id
  48. * @param $groupbuy_data
  49. * @return array|\multitype
  50. */
  51. public function editFreeshipping($data)
  52. {
  53. $freeshipping_id = $data[ 'freeshipping_id' ];
  54. unset($data[ 'freeshipping_id' ]);
  55. $data[ 'update_time' ] = time();
  56. $area_ids = json_decode($data[ 'area_ids' ], true);
  57. if (!empty($area_ids)) {
  58. foreach ($area_ids[ '3' ] as $k => $v) {
  59. if (!empty($area_ids[ '3' ])) {
  60. foreach ($v as $area_id) {
  61. //判断该城市是否已存在
  62. $count = model('promotion_freeshipping')->getCount(
  63. [
  64. [ 'site_id', '=', $data[ 'site_id' ] ],
  65. [ 'area_ids', 'like', '%' . $area_id . '%' ],
  66. [ 'freeshipping_id', '<>', $freeshipping_id ]
  67. ]
  68. );
  69. if ($count > 0) {
  70. return $this->error('', '指定地区城市不能重复');
  71. }
  72. }
  73. }
  74. }
  75. }
  76. $res = model('promotion_freeshipping')->update($data,
  77. [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'freeshipping_id', '=', $freeshipping_id ] ]
  78. );
  79. return $this->success($res);
  80. }
  81. /**
  82. * 删除满额包邮活动
  83. * @param $groupbuy_id
  84. * @param $site_id
  85. * @return array|\multitype
  86. */
  87. public function deleteFreeshipping($freeshipping_id, $site_id)
  88. {
  89. $list = model('promotion_freeshipping')->delete([ [ 'freeshipping_id', '=', $freeshipping_id ], [ 'site_id', '=', $site_id ] ]);
  90. return $this->success($list);
  91. }
  92. /**
  93. * 获取信息
  94. * @param array $condition
  95. * @param string $field
  96. * @return array
  97. */
  98. public function getFreeshippingInfo($condition = [], $field = '*')
  99. {
  100. $res = model('promotion_freeshipping')->getInfo($condition, $field);
  101. return $this->success($res);
  102. }
  103. /**
  104. * 获取满额包邮分页列表
  105. * @param array $condition
  106. * @param number $page
  107. * @param string $page_size
  108. * @param string $order
  109. * @param string $field
  110. */
  111. public function getFreeshippingPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  112. {
  113. $list = model('promotion_freeshipping')->pageList($condition, $field, $order, $page, $page_size);
  114. return $this->success($list);
  115. }
  116. /********************************************************************* 订单核验是否符合地区 start*****************************************************************************/
  117. /**
  118. * 是否符合满额包邮
  119. * @param $money
  120. * @param $district_id
  121. * @param $site_id
  122. * @return array
  123. */
  124. public function calculate($money, $district_id, $site_id)
  125. {
  126. $condition = array (
  127. [ 'price', "<=", $money ],
  128. [ 'site_id', "=", $site_id ],
  129. [ 'area_ids', 'like', '%"' . $district_id . '"%' ]
  130. );
  131. $info = model('promotion_freeshipping')->getInfo($condition, '*');
  132. if (!empty($info)) {
  133. return $this->success($info);
  134. } else {
  135. return $this->error();
  136. }
  137. }
  138. /********************************************************************* 订单核验是否符合地区 end*****************************************************************************/
  139. }