Offpayarea.php 2.9 KB

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