ShopGoods.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 $CATEGORY_TYPE 商品分类
  12. * @property string $SELL_TYPE 允许购买方式
  13. * @property int $GOODS_NO 商品编号
  14. * @property string $UNIT 单位
  15. * @property string $COVER 商品封面
  16. * @property int $IMAGES 商品图片
  17. * @property string $CONTENT 商品内容
  18. * @property string $SELL_PRICE_STANDARD 标准价格
  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. 'id' => 1,
  34. 'name' => 'Account Balance', //余额购买
  35. 'label' => 'cash',
  36. 'language' => 'shopListAccountBalance',
  37. ],
  38. // 2 => [
  39. // 'id' => 2,
  40. // 'name' => '复消兑换',
  41. // ],
  42. // 3 => [
  43. // 'id' => 3,
  44. // 'name' => '兑换点数',
  45. // 'label' => 'exchange',
  46. // ],
  47. 4 => [
  48. 'id' => 4,
  49. 'name' => 'Travel Bonus',
  50. 'label' => 'tourism_points',
  51. 'language' => 'shopListPayTravelBonus',
  52. ],
  53. 5 => [
  54. 'id' => 5,
  55. 'name' => 'Car Fund',
  56. 'label' => 'garage_points',
  57. 'language' => 'shopListPayCarFund',
  58. ],
  59. 6 => [
  60. 'id' => 6,
  61. 'name' => 'Villa Fund',
  62. 'label' => 'villa_points',
  63. 'language' => 'shopListPayVillaFund',
  64. ],
  65. 7 => [
  66. 'id' => 7,
  67. 'name' => 'PayStack',
  68. 'label' => 'pay_stack',
  69. 'language' => 'saleTypePayStack',
  70. ],
  71. ];
  72. const GOODS_TYPE = [
  73. 1 =>[
  74. 'name'=>'国内商品',//国内商品
  75. 'discount'=>'50',
  76. 'language' => 'shopGoodTypeDomestic',
  77. ],
  78. 2 =>[
  79. 'name'=>'进口商品',//进口商品
  80. 'discount'=>'60',
  81. 'language' => 'shopGoodTypeImport',
  82. ],
  83. ];
  84. const GIFT_TYPE = [
  85. 1 =>[
  86. 'name'=>'1st Purchase',//报单区
  87. ],
  88. 2 =>[
  89. 'name'=>'Repeat Purchase',//复消区
  90. ],
  91. // 3 =>[
  92. // 'name'=>'Office Entry area',//工作室报单
  93. // ],
  94. // 4 =>[
  95. // 'name'=>'Office Reselling area',//工作室复消
  96. // ],
  97. ];
  98. const STATUS_NAME = [
  99. 1 => 'On sale',//已上架
  100. 0 => 'Sold out',//已下架
  101. ];
  102. const CATEGORY_TYPE = [
  103. [
  104. 'id' => 1,
  105. 'name' => 'Standard Products',//普通商品
  106. 'sell_type' => [
  107. self::SALE_TYPE[1],
  108. // self::SALE_TYPE[3],
  109. self::SALE_TYPE[7],
  110. ]
  111. ],
  112. // [
  113. // 'id' => 4,
  114. // 'name' => 'Travel bonus products',//旅游积分商品
  115. // 'sell_type' => [
  116. // self::SALE_TYPE[4]
  117. // ]
  118. // ],
  119. [
  120. 'id' => 5,
  121. 'name' => 'Car Fund Products',
  122. 'sell_type' => [
  123. self::SALE_TYPE[5]
  124. ]
  125. ],
  126. [
  127. 'id' => 6,
  128. 'name' => 'Villa Fund Products',
  129. 'sell_type' => [
  130. self::SALE_TYPE[6]
  131. ]
  132. ],
  133. ];
  134. /**
  135. * @inheritdoc
  136. */
  137. public static function tableName()
  138. {
  139. return '{{%SHOP_GOODS}}';
  140. }
  141. /**
  142. * @inheritdoc
  143. */
  144. public function rules()
  145. {
  146. return [
  147. [['SELL_DISCOUNT','GOODS_NAME', 'CATE_ID','GIFT_TYPE', 'GOODS_NO', 'PRICE_PV','STORE_NUMS', 'SELL_TYPE', 'CATEGORY_TYPE', 'SELL_PRICE_STANDARD'], 'required'],
  148. [['STORE_NUMS'], 'integer'],
  149. [['PRICE_PV','POINT', 'CATEGORY_TYPE' ,'SELL_PRICE_STANDARD'], 'number'],
  150. [['ID','CATE_ID', 'GOODS_NO','GIFT_TYPE'], 'string', 'max' => 32],
  151. [['UNIT'], 'string', 'max' => 16],
  152. [['COVER', 'GOODS_NAME'], 'string', 'max' => 255],
  153. [['IMAGES','CONTENT'], 'string', 'max' => 4000],
  154. [['GOODS_NAME'], 'unique'],
  155. [['ID'], 'unique'],
  156. ];
  157. }
  158. /**
  159. * @inheritdoc
  160. */
  161. public function attributeLabels()
  162. {
  163. return [
  164. 'ID' => 'ID',
  165. 'GOODS_NAME' => '商品名称',
  166. 'CATE_ID' => '所属分类ID',
  167. 'SELL_DISCOUNT' => '会员折扣',
  168. 'GIFT_TYPE' => '商品类型',
  169. 'CATEGORY_TYPE' => '商品分类',
  170. 'SELL_TYPE' => '出售方式',
  171. 'GOODS_NO' => '商品编号',
  172. 'UNIT' => '商品单位',
  173. 'COVER' => '商品封面',
  174. 'IMAGES' => '商品图片',
  175. 'CONTENT' => '商品内容',
  176. 'SELL_PRICE_STANDARD' => 'US price($)',
  177. 'PRICE_PV' => '价格PV',
  178. 'STORE_NUMS' => '库存',
  179. 'STATUS' => '是否上架',
  180. 'IS_DEL' => '是否删除',
  181. 'CREATED_AT' => '创建时间',
  182. 'UPDATED_AT' => '更新时间',
  183. 'DELETED_AT' => '更新时间',
  184. 'SORT' => '排序',
  185. ];
  186. }
  187. /**
  188. * 判断提现状态
  189. * @param $nowStatus
  190. * @param $toStatus
  191. * @return string
  192. */
  193. public static function chkAuditStatus($nowStatus, $toStatus) {
  194. $statusName = self::STATUS_NAME;
  195. // $msg = 'The current product status is【' . $statusName[$nowStatus] . '】,cannot be set to【' . $statusName[$toStatus] . '】';// 当前商品状态为 无法设置为
  196. $msg = \Yii::t('ctx', 'shopSetProductStatusErrorNotice', [
  197. 'nowStatus' => $statusName[$nowStatus],
  198. 'newStatus' => $statusName[$toStatus]
  199. ]);
  200. switch ($toStatus) {
  201. // 下架
  202. case 0:
  203. if ($nowStatus == 1) {
  204. $msg = '';
  205. }
  206. break;
  207. //上架
  208. case 1:
  209. if ($nowStatus == 0) {
  210. $msg = '';
  211. }
  212. break;
  213. default:
  214. }
  215. return $msg;
  216. }
  217. /**
  218. * 支付方式
  219. * @return array
  220. */
  221. public static function payTypes(){
  222. return [
  223. 'cash'=>[
  224. 'name'=> \Yii::t('ctx', 'shopPayTypeCash')//余额支付
  225. ],
  226. // 'point'=>[
  227. // 'name'=>'积分支付' //积分支付
  228. // ],
  229. // 'exchange' => [
  230. // 'name' => '积分点数'
  231. // ],
  232. // 'tourism_points'=>[
  233. // 'name'=>'Travel Bonus'
  234. // ],
  235. 'garage_points' => [
  236. 'name' => \Yii::t('ctx', 'shopPayTypeGaragePoints')
  237. ],
  238. 'villa_points' => [
  239. 'name' => \Yii::t('ctx', 'shopPayTypeVillaFund')
  240. ],
  241. 'pay_stack' => [
  242. 'name' => 'PayStack'
  243. ],
  244. ];
  245. }
  246. // 获取商品类型
  247. public static function getGiftType() {
  248. return [
  249. 1 =>[
  250. 'name'=>\Yii::t('ctx', 'shopList1stPurchase'),//报单区
  251. ],
  252. 2 =>[
  253. 'name'=>\Yii::t('ctx', 'shopListRepeatPurchase'),//复消区
  254. ],
  255. // 3 =>[
  256. // 'name'=>\Yii::t('ctx', 'shopListEntryArea'),//工作室报单
  257. // ],
  258. // 4 =>[
  259. // 'name'=>\Yii::t('ctx', 'shopListResellingArea'),//工作室复消
  260. // ],
  261. ];
  262. }
  263. // 获取分类类型
  264. public static function getCategoryType() {
  265. return [
  266. [
  267. 'id' => 1,
  268. 'name' => \Yii::t('ctx', 'shopListStandardProducts'),//普通商品
  269. 'sell_type' => [
  270. self::SALE_TYPE[1],
  271. // self::SALE_TYPE[3],
  272. self::SALE_TYPE[7],
  273. ]
  274. ],
  275. // [
  276. // 'id' => 4,
  277. // 'name' => 'Travel bonus products',//旅游积分商品
  278. // 'sell_type' => [
  279. // self::SALE_TYPE[4]
  280. // ]
  281. // ],
  282. [
  283. 'id' => 5,
  284. 'name' => \Yii::t('ctx', 'shopListCarFundProducts'),
  285. 'sell_type' => [
  286. self::SALE_TYPE[5]
  287. ]
  288. ],
  289. [
  290. 'id' => 6,
  291. 'name' => \Yii::t('ctx', 'shopListVillaFundProducts'),
  292. 'sell_type' => [
  293. self::SALE_TYPE[6]
  294. ]
  295. ],
  296. ];
  297. }
  298. public static function getSaleType(): array
  299. {
  300. return array_map(function ($item) {
  301. $item['name'] = \Yii::t('ctx', $item['language']);
  302. return $item;
  303. }, self::SALE_TYPE);
  304. }
  305. public static function getGoodType(): array
  306. {
  307. return array_map(function ($item) {
  308. $item['name'] = \Yii::t('ctx', $item['language']);
  309. return $item;
  310. }, self::GOODS_TYPE);
  311. }
  312. }