ShopGoods.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. namespace common\models;
  3. /**
  4. * This is the model class for table "{{%SHOP_GOODS}}".
  5. *
  6. * @property string $ID
  7. * @property string $GOODS_NAME 商品名称
  8. * @property string $CATE_ID 所属分类ID
  9. * @property string $TYPE 商品来源
  10. * @property string $GIFT_TYPE 商品类型
  11. * @property string $SELL_TYPE 允许购买方式
  12. * @property int $GOODS_NO 商品编号
  13. * @property string $UNIT 单位
  14. * @property string $COVER 商品封面
  15. * @property int $IMAGES 商品图片
  16. * @property string $CONTENT 商品内容
  17. * @property string $SELL_PRICE 销售价格
  18. * @property string $MARKET_PRICE 市场价格
  19. * @property int $PRICE_PV 价格PV
  20. * @property int $POINT 兑换积分
  21. * @property int $STORE_NUMS 库存
  22. * @property int $IS_DEL 是否删除
  23. * @property int $CREATED_AT 创建时间
  24. * @property int $UPDATED_AT 更新时间
  25. * @property int $DELETED_AT 删除时间
  26. * @property int $STATUS 状态
  27. * @property string $SORT 排序
  28. */
  29. class ShopGoods extends \common\components\ActiveRecord
  30. {
  31. const SALE_TYPE = [
  32. 1 => [
  33. 'name' => '余额购买',
  34. ],
  35. 2 => [
  36. 'name' => '复消兑换',
  37. ],
  38. 3 => [
  39. 'name' => '积分兑换'
  40. ],
  41. ];
  42. const LOCAL_PAY = [
  43. 1 => [
  44. 'name' => '余额购买',
  45. ],
  46. 2 => [
  47. 'name' => '复消兑换',
  48. ],
  49. 3 => [
  50. 'name' => '积分兑换'
  51. ],
  52. ];
  53. const ONLINE_PAY = [
  54. // 4 => [
  55. // 'name' => 'IPay88'
  56. // ],
  57. 5 => [
  58. 'name' => '微信'
  59. ],
  60. 6 => [
  61. 'name' => '支付宝'
  62. ],
  63. ];
  64. const GOODS_TYPE = [
  65. 1 =>[
  66. 'name'=>'国内商品',
  67. 'discount'=>'50',
  68. ],
  69. 2 =>[
  70. 'name'=>'进口商品',
  71. 'discount'=>'60',
  72. ],
  73. ];
  74. const GIFT_TYPE = [
  75. 1 =>[
  76. 'name'=>'报单区',
  77. ],
  78. 2 =>[
  79. 'name'=>'复消区',
  80. ],
  81. 3 =>[
  82. 'name'=>'工作室报单',
  83. ],
  84. 4 =>[
  85. 'name'=>'工作室复消',
  86. ],
  87. ];
  88. const STATUS_NAME = [
  89. 1 => '已上架',
  90. 0 => '已下架',
  91. ];
  92. /**
  93. * @inheritdoc
  94. */
  95. public static function tableName()
  96. {
  97. return '{{%SHOP_GOODS}}';
  98. }
  99. /**
  100. * @inheritdoc
  101. */
  102. public function rules()
  103. {
  104. return [
  105. [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'GOODS_NO', 'SELL_PRICE','MARKET_PRICE','PRICE_PV','STORE_NUMS'], 'required'],
  106. [['STORE_NUMS'], 'integer'],
  107. [['SELL_PRICE','MARKET_PRICE','PRICE_PV','POINT'], 'number'],
  108. [['ID','CATE_ID', 'GOODS_NO','SELL_TYPE','GIFT_TYPE'], 'string', 'max' => 32],
  109. [['UNIT'], 'string', 'max' => 16],
  110. [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
  111. [['IMAGES','CONTENT'], 'string', 'max' => 4000],
  112. [['GOODS_NAME'], 'unique'],
  113. [['ID'], 'unique'],
  114. ];
  115. }
  116. /**
  117. * @inheritdoc
  118. */
  119. public function attributeLabels()
  120. {
  121. return [
  122. 'ID' => 'ID',
  123. 'GOODS_NAME' => '商品名称',
  124. 'CATE_ID' => '所属分类ID',
  125. // 'TYPE' => '商品来源',
  126. 'SELL_DISCOUNT' => '会员折扣',
  127. 'GIFT_TYPE' => '商品类型',
  128. 'SELL_TYPE' => '出售方式',
  129. 'GOODS_NO' => '商品编号',
  130. 'UNIT' => '商品单位',
  131. 'COVER' => '商品封面',
  132. 'IMAGES' => '商品图片',
  133. 'CONTENT' => '商品内容',
  134. 'SELL_PRICE' => '销售价格',
  135. 'MARKET_PRICE' => '市场价格',
  136. 'PRICE_PV' => '价格PV',
  137. 'POINT' => '兑换点数',
  138. 'STORE_NUMS' => '库存',
  139. 'STATUS' => '是否上架',
  140. 'IS_DEL' => '是否删除',
  141. 'CREATED_AT' => '创建时间',
  142. 'UPDATED_AT' => '更新时间',
  143. 'DELETED_AT' => '更新时间',
  144. 'SORT' => '排序',
  145. ];
  146. }
  147. /**
  148. * 判断提现状态
  149. * @param $nowStatus
  150. * @param $toStatus
  151. * @return string
  152. */
  153. public static function chkAuditStatus($nowStatus, $toStatus) {
  154. $statusName = self::STATUS_NAME;
  155. $msg = '当前商品状态为【' . $statusName[$nowStatus] . '】,无法设置为【' . $statusName[$toStatus] . '】';
  156. switch ($toStatus) {
  157. // 下架
  158. case 0:
  159. if ($nowStatus == 1) {
  160. $msg = '';
  161. }
  162. break;
  163. //上架
  164. case 1:
  165. if ($nowStatus == 0) {
  166. $msg = '';
  167. }
  168. break;
  169. default:
  170. }
  171. return $msg;
  172. }
  173. /**
  174. * 支付方式
  175. * @return array
  176. */
  177. public static function payTypes(){
  178. return [
  179. 'cash'=>[
  180. 'name'=>'消费点数支付'
  181. ],
  182. 'point'=>[
  183. 'name'=>'复销点数支付'
  184. ],
  185. 'exchange' => [
  186. 'name' => '无业绩兑换点数'
  187. ],
  188. 'online' => [
  189. 'name' => 'IPay88'
  190. ],
  191. 'WECHAT' => [
  192. 'name' => '微信正扫',
  193. ],
  194. 'WAPWECHAT' => [
  195. 'name' => '微信WAP',
  196. ],
  197. 'ALIPAY' => [
  198. 'name' => '支付宝正扫',
  199. ],
  200. 'WEBSITEALIPAY' => [
  201. 'name' => '支付宝WAP',
  202. ],
  203. ];
  204. }
  205. public static function getPayMethod($device = 'local')
  206. {
  207. $result = [];
  208. if ($device == 'website') {
  209. // 正扫/主扫
  210. $result = [
  211. 'WECHAT' => [
  212. 'name' => '微信',
  213. ],
  214. 'ALIPAY' => [
  215. 'name' => '支付宝',
  216. ],
  217. ];
  218. }
  219. if ($device == 'mobile') {
  220. // H5/WAP
  221. $result = [
  222. 'WAPWECHAT' => [
  223. 'name' => '微信',
  224. ],
  225. 'WEBSITEALIPAY' => [
  226. 'name' => '支付宝',
  227. ],
  228. ];
  229. }
  230. if ($device == 'local') {
  231. $result = [
  232. 'cash'=>[
  233. 'name'=>'消费点数支付'
  234. ],
  235. 'point'=>[
  236. 'name'=>'复销点数支付'
  237. ],
  238. 'exchange' => [
  239. 'name' => '无业绩兑换点数'
  240. ],
  241. ];
  242. }
  243. return $result;
  244. }
  245. }