Offpayarea.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * ============================================================================
  12. * 数据层模型
  13. */
  14. class Offpayarea extends BaseModel
  15. {
  16. /**
  17. * 增加某店铺设置
  18. * @access public
  19. * @author csdeshang
  20. * @param array $data 参数内容
  21. * @return bool
  22. */
  23. public function addOffpayarea($data)
  24. {
  25. return Db::name('offpayarea')->insert($data);
  26. }
  27. /**
  28. * 取得某店铺设置
  29. * @access public
  30. * @author csdeshang
  31. * @param array $condition 条件
  32. * @return array
  33. */
  34. public function getOffpayareaInfo($condition)
  35. {
  36. return Db::name('offpayarea')->where($condition)->find();
  37. }
  38. /**
  39. * 更新某店铺设置
  40. * @access public
  41. * @author csdeshang
  42. * @param array $condition 条件
  43. * @param array $data 数据
  44. * @return bool
  45. */
  46. public function editOffpayarea($condition, $data)
  47. {
  48. return Db::name('offpayarea')->where($condition)->update($data);
  49. }
  50. /**
  51. * 某县级地区是否支持货到付款
  52. * @access public
  53. * @author csdeshang
  54. * @param int $area_id 地区ID
  55. * @param int $store_id 店铺ID(目前只会传平台店铺)
  56. * @return bool
  57. */
  58. public function checkSupportOffpay($area_id, $store_id)
  59. {
  60. if (empty($area_id)) return false;
  61. $area = $this->getOffpayareaInfo(array('store_id' => $store_id));
  62. if (!empty($area['area_id'])) {
  63. $area_id_array = unserialize($area['area_id']);
  64. } else {
  65. $area_id_array = array();
  66. }
  67. if (empty($area_id_array)) {
  68. $area_id_array = array();
  69. }
  70. return in_array($area_id, $area_id_array) ? true : false;
  71. }
  72. /**
  73. * 某县级地区是否支持货到付款(多个店铺)
  74. * @access public
  75. * @author csdeshang
  76. * @param int $area_id 地区ID
  77. * @param array $store_ids 店铺IDs
  78. * @return array
  79. */
  80. public function checkSupportOffpayBatch($area_id, array $store_ids)
  81. {
  82. if (empty($area_id))
  83. return array_fill($store_ids, false);
  84. $area = Db::name('offpayarea')->where('store_id', 'in', $store_ids)->select()->toArray();
  85. $area = ds_change_arraykey($area, 'store_id');
  86. $ret = array();
  87. foreach ($store_ids as $sid) {
  88. $ret[$sid] = false;
  89. if (empty($area[$sid]['area_id']))
  90. continue;
  91. $area_id_array = unserialize($area[$sid]['area_id']);
  92. if (!is_array($area_id_array))
  93. continue;
  94. if (!in_array($area_id, $area_id_array))
  95. continue;
  96. $ret[$sid] = true;
  97. }
  98. return $ret;
  99. }
  100. }