store_waybill.model.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * 店铺运单模板模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class store_waybillModel extends Model{
  11. const STORE_WAYBILL_DEFAULT = 1;
  12. const STORE_WAYBILL_UNDEFAULT = 0;
  13. public function __construct(){
  14. parent::__construct('store_waybill');
  15. }
  16. /**
  17. * 读取列表
  18. * @param array $condition
  19. *
  20. */
  21. public function getStoreWaybillList($condition, $order = '') {
  22. $model_waybill = Model('waybill');
  23. $store_waybill_list = $this->where($condition)->order($order)->select();
  24. foreach ($store_waybill_list as $key => $value) {
  25. $store_waybill_list[$key]['is_default_text'] = $value['is_default'] ? '是' : '否';
  26. $store_waybill_list[$key]['waybill_pixel_top'] = $value['store_waybill_top'] * $model_waybill::WAYBILL_PIXEL_CONSTANT;
  27. $store_waybill_list[$key]['waybill_pixel_left'] = $value['store_waybill_left'] * $model_waybill::WAYBILL_PIXEL_CONSTANT;
  28. }
  29. return $store_waybill_list;
  30. }
  31. /**
  32. * 读取列表包含模板信息
  33. *
  34. */
  35. public function getStoreWaybillListWithWaybillInfo($store_id, $store_express) {
  36. $condition = array();
  37. $condition['store_waybill.store_id'] = $store_id;
  38. $condition['store_waybill.express_id'] = array('in', $store_express);
  39. $field = 'store_waybill.*,waybill.waybill_image,waybill.waybill_width,waybill.waybill_height';
  40. return $this->table('store_waybill,waybill')->join('inner')->on('store_waybill.waybill_id=waybill.waybill_id')->where($condition)->field($field)->order($order)->select();
  41. }
  42. /**
  43. * 读取单条记录
  44. * @param array $condition
  45. *
  46. */
  47. public function getStoreWaybillInfo($condition) {
  48. $store_waybill_info = $this->where($condition)->find();
  49. if(!empty($store_waybill_info)) {
  50. $store_waybill_info['store_waybill_data'] = unserialize($store_waybill_info['store_waybill_data']);
  51. }
  52. return $store_waybill_info;
  53. }
  54. /*
  55. * 增加
  56. * @param array $param
  57. * @return bool
  58. */
  59. public function addStoreWaybill($store_waybill_info){
  60. $model_waybill = Model('waybill');
  61. $item_list = $model_waybill->getWaybillItemList();
  62. foreach ($item_list as $key => $value) {
  63. $item_list[$key]['show'] = true;
  64. }
  65. $store_waybill_info['store_waybill_data'] = serialize($item_list);
  66. return $this->insert($store_waybill_info);
  67. }
  68. /*
  69. * 更新
  70. * @param array $update
  71. * @param array $condition
  72. * @return bool
  73. */
  74. public function editStoreWaybill($update, $condition, $data = array()) {
  75. if(!empty($data)) {
  76. $update['store_waybill_data'] = $this->_getStoreWaybillData($data);
  77. }
  78. return $this->where($condition)->update($update);
  79. }
  80. /**
  81. * 获取处理后的自定义数据内容
  82. * @param array $data
  83. * @param array $condition
  84. * @return bool
  85. */
  86. private function _getStoreWaybillData($data) {
  87. $model_waybill = Model('waybill');
  88. $item_list = $model_waybill->getWaybillItemList();
  89. foreach ($item_list as $key => $value) {
  90. if($data[$key]) {
  91. $item_list[$key]['show'] = true;
  92. } else {
  93. $item_list[$key]['show'] = false;
  94. }
  95. }
  96. return serialize($item_list);
  97. }
  98. /**
  99. * 设置默认打印模板
  100. * @param int $store_waybill_id
  101. * @param int $store_id
  102. * @return bool
  103. */
  104. public function editStoreWaybillDefault($store_waybill_id, $store_id) {
  105. $store_waybill_id = intval($store_waybill_id);
  106. if($store_waybill_id <= 0) {
  107. return false;
  108. }
  109. //解除原默认设置
  110. $this->editStoreWaybill(array('is_default' => self::STORE_WAYBILL_UNDEFAULT), array('store_id' => $store_id));
  111. $condition = array();
  112. $condition['store_waybill_id'] = $store_waybill_id;
  113. $condition['store_id'] = $store_id;
  114. return $this->editStoreWaybill(array('is_default' => self::STORE_WAYBILL_DEFAULT), $condition);
  115. }
  116. /*
  117. * 删除
  118. * @param array $condition
  119. * @return bool
  120. */
  121. public function delStoreWaybill($condition) {
  122. return $this->where($condition)->delete();
  123. }
  124. }