ShopGoods.php 8.6 KB

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