ShopModel.class.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace Common\Model;
  3. class ShopModel extends \Think\Model
  4. {
  5. protected $keyS = 'Shop';
  6. public function check_coin()
  7. {
  8. $check_coin = (APP_DEBUG ? null : S('check_coin' . $this->keyS));
  9. if (!$check_coin) {
  10. $coin_list = C('coin');
  11. if (is_array($coin_list)) {
  12. foreach ($coin_list as $k => $v) {
  13. $coin_arr[$v['name']] = $v['title'];
  14. }
  15. unset($k);
  16. unset($v);
  17. }
  18. else {
  19. $coin_arr = null;
  20. }
  21. if ($coin_arr) {
  22. $Shop_Coin_DbFields = M('ShopCoin')->getDbFields();
  23. foreach ($coin_arr as $k => $v) {
  24. if (!in_array($k, $Shop_Coin_DbFields)) {
  25. M()->execute('ALTER TABLE `tw_shop_coin` ADD COLUMN `' . $k . '` VARCHAR(50) NOT NULL COMMENT \'' . $v . '\' AFTER `shopid`;');
  26. }
  27. }
  28. }
  29. S('check_coin' . $this->keyS, 1);
  30. }
  31. }
  32. public function shop_type_list()
  33. {
  34. $shop_type_list = (APP_DEBUG ? null : S('shop_type_list' . $this->keyS));
  35. if (!$shop_type_list) {
  36. $list = M('ShopType')->where(array('status' => 1))->select();
  37. if ($list) {
  38. foreach ($list as $k => $v) {
  39. $shop_type_list[$v['name']] = $v['title'];
  40. }
  41. }
  42. else {
  43. $shop_type_list = null;
  44. }
  45. S('shop_type_list' . $this->keyS, $shop_type_list);
  46. }
  47. return $shop_type_list;
  48. }
  49. public function getShopName($id = NULL)
  50. {
  51. if (empty($id)) {
  52. return null;
  53. }
  54. $shop_getShopName = (APP_DEBUG ? null : S('shop_getShopName' . $id . $this->keyS));
  55. if (!$shop_getShopName) {
  56. $shop_getShopName = M('Shop')->where(array('id' => $id))->getField('name');
  57. S('shop_getShopName' . $id . $this->keyS, $shop_getShopName);
  58. }
  59. return $shop_getShopName;
  60. }
  61. public function getShopId($name = NULL)
  62. {
  63. if (empty($name)) {
  64. return null;
  65. }
  66. $shop_getShopId = (APP_DEBUG ? null : S('shop_getShopId' . $this->keyS));
  67. if (!$shop_getShopId) {
  68. $shop_getShopId = M('Shop')->where(array(
  69. 'name' => array('like', '%' . $name . '%')
  70. ))->getField('id');
  71. S('shop_getShopId' . $this->keyS, $shop_getShopId);
  72. }
  73. return $shop_getShopId;
  74. }
  75. public function tongbu()
  76. {
  77. $shop_tongbu = (APP_DEBUG ? null : S('shop_tongbu' . $this->keyS));
  78. if (!$shop_tongbu) {
  79. $shop_list = M('Shop')->select();
  80. $shop_coin_list = M('ShopCoin')->select();
  81. if (is_array($shop_coin_list)) {
  82. foreach ($shop_coin_list as $k => $v) {
  83. $shop_coin_arr[$v['shopid']] = $v['id'];
  84. }
  85. }
  86. if (is_array($shop_list)) {
  87. foreach ($shop_list as $k => $v) {
  88. $shop_list_arr[$v['id']] = $v;
  89. if (!$shop_coin_arr[$v['id']]) {
  90. M('ShopCoin')->add(array('shopid' => $v['id']));
  91. }
  92. }
  93. }
  94. if (is_array($shop_coin_list) && is_array($shop_list)) {
  95. foreach ($shop_coin_list as $k => $v) {
  96. $shop_coin_arr[$v['shopid']] = $v['id'];
  97. if (!$shop_list_arr[$v['shopid']]) {
  98. M('ShopCoin')->where(array('id' => $v['id']))->delete();
  99. }
  100. }
  101. }
  102. S('shop_tongbu' . $this->keyS, 1);
  103. }
  104. }
  105. public function fangshi($shopid = NULL)
  106. {
  107. if (empty($shopid)) {
  108. return null;
  109. }
  110. $shop_fangshi = (APP_DEBUG ? null : S('shop_fangshi' . $this->keyS . $shopid));
  111. if (!$shop_fangshi) {
  112. $list = M('ShopCoin')->where(array('shopid' => $shopid))->find();
  113. foreach ($list as $k => $v) {
  114. if (($k != 'id') && ($k != 'shopid')) {
  115. if ($v) {
  116. if ($k == 'cny') {
  117. $shop_fangshi[$k] = 1;
  118. }
  119. else {
  120. $new_price = D('Market')->get_new_price($k . '_cny');
  121. if ($new_price) {
  122. $shop_fangshi[$k] = $new_price;
  123. }
  124. else {
  125. $shop_fangshi[$k] = 1;
  126. }
  127. }
  128. }
  129. }
  130. }
  131. S('shop_fangshi' . $this->keyS . $shopid, $shop_fangshi);
  132. }
  133. return $shop_fangshi;
  134. }
  135. public function get_goods($userid = NULL)
  136. {
  137. if (empty($userid)) {
  138. return null;
  139. }
  140. $shop_get_goods = (APP_DEBUG ? null : S('shop_get_goods' . $this->keyS . $userid));
  141. if (!$shop_get_goods) {
  142. $list = M('UserGoods')->where(array('userid' => $userid))->select();
  143. foreach ($list as $k => $v) {
  144. $shop_get_goods[$v['id']] = $v['name'];
  145. }
  146. S('shop_get_goods' . $this->keyS . $userid, $shop_get_goods);
  147. }
  148. return $shop_get_goods;
  149. }
  150. public function setStatus($id = NULL, $type = NULL, $mobile = 'Shop')
  151. {
  152. if (empty($id)) {
  153. return null;
  154. }
  155. if (empty($type)) {
  156. return null;
  157. }
  158. if (strpos(',', $id)) {
  159. $id = implode(',', $id);
  160. }
  161. $where['id'] = array('in', $id);
  162. switch (strtolower($type)) {
  163. case 'forbid':
  164. $data = array('status' => 0);
  165. break;
  166. case 'resume':
  167. $data = array('status' => 1);
  168. break;
  169. case 'repeal':
  170. $data = array('status' => 2, 'endtime' => time());
  171. break;
  172. case 'delete':
  173. $data = array('status' => -1);
  174. break;
  175. case 'del':
  176. if (M($mobile)->where($where)->delete()) {
  177. return true;
  178. }
  179. else {
  180. return null;
  181. }
  182. break;
  183. default:
  184. return null;
  185. }
  186. if (M($mobile)->where($where)->save($data)) {
  187. return true;
  188. }
  189. else {
  190. return null;
  191. }
  192. }
  193. }
  194. ?>